Answers from Adapter Design Pattern Chapter in Alan Shalloway's book,
Answers supplied by Shalloway and Trott
2. What is the intent of the Adapter pattern?
The intent of the Adapter is to match an existing object that is beyond your control to a particular interface.
3. What are the consequences of the Adapter pattern? Give an example.
A consequence is that the pattern allows for preexisting objects to fit into new class structures without being limited by their interfaces (p. 102). The example in the book is the drawing program that wants to use an existing Circle object but the existing object doesn't provide exactly the same methods as the rest of the system. The Adapter provides a translation to these methods.
4. Which object-oriented concept is being used to define the relationship between Shape and Points, Lines, and Squares?
Polymorphism
5. What is the most common use for the Adapter pattern?
Was asked in section To allow for continued use of polymorphism. It is often used in conjunction with other design patterns.
6. What does the Adapter pattern free you from worrying about?
Adapter frees me from worrying about the interfaces of existing classes when doing a design. If the class doesn't do what I need, I can create an Adapter to give it the correct interface. (p. 103)
2. "The Circle object wraps the XXCircle object." What does this mean?
Circle completely insulates XXCircle from the system. Circle manifests the entire behavior of XXCircle to the system, although with a different interface / way of accessing XXCircle.
3. The Façade pattern and the Adapter pattern may seem similar. What is the essential difference between the two?
In both cases, there is a preexisting class or classes that have functionality I need. In both cases, I create an intermediary object with interfaces that my system wants to use and that has responsibility for mapping that to the preexisting class. Both Façade and Adapter are wrappers.
The Adapter is used when the client already has predefined interfaces that it expects to use and when I need to use polymorphism.
The Façade is used when I need a simpler interface to the existing object.
4. Here is an example of an Adapter that comes from outside of software. A translator at the UN lets diplomats from different countries reason about and argue for the positions of their own countries in their own languages. The translator makes "dynamically equivalent" representations from one language to the other so that the concepts are communicated in the way that the recipient expects and needs to hear it.
What is another example from real life that illustrates an Adapter?
Another example could be a travel agent, seen as the common interface between a passenger making arrangements and an airline with its own systems. Each has competing systems, speaking different languages