Chapter 9. The Adapter Pattern

The Adapter pattern converts the programming interface of one class into that of another. You use adapters whenever you want unrelated classes to work together in a single program. The concept of an adapter is thus pretty simple: You write a class that has the desired interface and then make it communicate with the class that has a different interface. There are two ways to do this: by inheritance and by object composition. In the first, you derive a new class from the nonconforming one and add the methods that you need to make the new derived class match the desired interface. In the second, you include the original class inside the new one and create the methods to translate calls within the new class. These two ...

Get Java™ Design Patterns: A Tutorial now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.