Java Reference
In-Depth Information
with the application it plugs into that the application won't expand its use of a
PrintStream
object's behavior. In fact, although the word
adapter
appears in the name of the
MessageAdapter
class, you might question whether
MessageAdapter
is an instance of
the A
DAPTER
pattern.
CHALLENGE 3.5
Provide an argument that
MessageAdapter
, as it appears in Figure 3.8, is or is not
an example of A
DAPTER
.
In answering Challenge 2.4, you explained the value of the
Window-Adapter
class.
The
MouseAdapter
class, as Figure 3.9 shows, is another example of a class that stubs out
the requirements of a registration interface.
Figure 3.9. The
MouseAdapter
class stubs out the requirements of the
MouseListener
interface.
CHALLENGE 3.6
Provide an argument that you are applying the A
DAPTER
pattern when you use
the
MouseAdapter
class. Alternatively, argue that this is not the case.
Summary
The
JTable
component in Swing is a good example of a class whose developers applied the
A
DAPTER
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