Summary

The JTable component in Swing is a good example of a class whose developers applied the ADAPTER pattern. A JTable component sets itself up as a client that needs table information as defined by the TableModel interface. This makes it easy for you to write an adapter that feeds the table data from domain objects, such as instances of the Rocket class.

To use JTable, you need to write an object adapter that delegates calls to instances of an existing class. Two aspects of JTable prevent you from using a class adapter. First, you will usually create your table adapter as a subclass of AbstractTableModel, so you can't also subclass your existing class. Second, the JTable class requires a collection of objects, and only an object adapter can ...

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.