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, or by using composition, where the old object becomes a class attribute. The adapter pattern is also known as a wrapper.
In cases where the old code needs to make use of the new code, and vice-versa, we need to use a special adapter called a two-way...