Implementing the Adapter pattern
Let’s explore two common uses of the Adapter pattern. That is, creating an Adapter to bridge the gap between two incompatible class interfaces or building an Adapter to simply wrap an existing set of functions with an OO interface.
We will start with the usage of an Adapter providing a connector between two (or more) incompatible classes. The Adaptee will be a well-tested class that we would like to reuse (but which has an undesirable interface), and the Target classes will be those specified in our OO design for an application in the making. Let’s now specify an Adapter to allow our Adaptee to work with our Target classes.
Using an Adapter to provide a necessary interface to an existing class
To implement the Adapter pattern, we will first need to identify our Adaptee class. We will then create an Adapter class to modify the interface of the Adaptee. We will also identify our Target class, representing the class we need to model...