Incompatible object collaboration with the adapter pattern
The main goal of the adapter pattern is to connect the source class interface to another interface that clients will expect. The adapter pattern allows classes to work together that otherwise couldn’t due to an incompatible abstraction or implementation. It is considered one of the most common patterns and is one of the Gang of Four (GoF) design patterns.
Motivation
The adapter pattern is also known as wrapper. An adapter wraps the behavior of the adaptee (connected class) and allows access to the adaptee without modification using an already existing interface. Commonly, an adaptee uses an incompatible interface, and an adapter consolidates such behavior and transparently provides access to the required functionality.
Finding it in the JDK
The java.base
module provides multiple implementations of the adapter pattern. The Collections
utility class from the java.util
package provides a list
method, which accepts...