O'Reilly logo

Design Patterns Java™ Workbook by Steven John Metsker

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

Class and Object Adapters

The designs in Figures 3.1 and 3.2 are class adapters, which adapt through subclassing. When you need to apply ADAPTER, you may not be able to subclass the class whose methods you need to adapt. In some cases, you may need to create an adapter that adapts information from more than one object. You may also find that the interface you need to adapt to is not a Java interface but rather an abstract class that you must subclass. In such cases, you need to create an object adapter—an adapter that uses delegation rather than subclassing.

A good example of a class that requires you to write an object adapter is the JTable class in javax.swing. This class creates a GUI (graphical user interface) table component filled with ...

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