O'Reilly logo

Java™ Design Patterns: A Tutorial by James W. Cooper

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required