The Adapter Pattern
C++ Project Example
Link: Turkey and Duck
Theory
The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets clases work together that couldn’t otherwise because of incompatible interfaces.
Object and Class Adapters
- Object Adapters: The Adapter class is composed with the object of Adaptee
- Class Adapters: The Adapter class subclasses both the Target and Adaptee interfaces
Class Diagram
classDiagram
class Target {
void request()
}
class Adaptee {
void specificRequest()
}
class ClientGame {
// main.cpp
}
class Adapter {
Adaptee adaptee
void request()
}
ClientGame "interacts with" --> Target
Adapter "implements" ..> Target
Adapter "composition" --> Adaptee