The adapter pattern
This pattern is often used when dealing with frameworks, libraries, and APIs to easily "adapt" the old and existing interfaces to the new requirements of a program.
Roles
The adapter pattern converts the interface of another existing class into an interface waited by the existing clients to allow them to work together. Thanks to this pattern, you can integrate components for which you normally cannot modify the source code and things that often appear with the use of a framework.
Note that you should avoid using this pattern if you already have source code access to the component.
Design
The generic class diagram of the pattern is as follows:
Participants
In the preceding diagram, you can see the four participants of this pattern:
ITarget
: This introduces the method signature of the object through this interfaceClient
: The client interacts with objects that implement theITarget
interfaceAdapter
: This class implements the method of theITarget
interface and invokes...