Adapter Pattern Structure and Participants
The Adapter Pattern has two common implementations: Class Adapter (uses inheritance) and Object Adapter (uses composition). Object Adapter is more commonly used because it follows the composition over inheritance principle.
Object Adapter Structure (Recommended)
Participants and Responsibilities
Target Interface: Defines the domain-specific interface that the Client uses. This is what the client code expects to work with.
Adapter: Implements the Target interface and holds a reference to the Adaptee. It translates calls from the Target interface to the Adaptee's interface. The translation logic resides here.
Adaptee: The existing class with an incompatible interface that needs adapting. It contains useful functionality but cannot be used directly by the client.
Client: Collaborates with objects conforming to the Target interface. It remains unaware of the Adapter's existence or the Adaptee's incompatible interface.
Call Flow
2. Adapter translates the call
3. Adapter calls adaptee.specificRequest()
4. Adaptee performs the work
5. Adapter returns result to Client (if needed)