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

Get Design Patterns Java™ Workbook 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.