Adapter pattern
The adapter pattern provides a solution for code reusability; it adapts/wraps existing old code to new interfaces, interfaces that were unknown at the design time of the original code. In 1987, when the PS/2 port was designed, no one imagined that it would be connected to a USB bus designed nine years later. Yet we can still use an old PS/2 keyboard in our newest computer by connecting it to the USB port.
The adapter pattern is commonly used when working with legacy code, since by wrapping the existing code and adapting it to the new code interface, we instantly gain access to the old, already-tested, functionality. This can be done either by using multiple inheritances, made possible in Java 8 by default interface implementation, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access