Java Reference
In-Depth Information
System.out.println(Arrays.deepToString(folks));
The output produced by this fragment is:
[[Ann, Arthur, Arnie], [Bill, Barbara, Ben, Brenda, Brian], [Charles, Catherine]]
OBSERVABLE AND OBSERVER OBJECTS
The Observable class provides an interesting mechanism for communicating a change in one class object
to a number of other class objects. One use for this mechanism is in graphical user interface (GUI) program-
ming where you often have one object representing all the data for the application — a text document, for
example, or a geometric model of a physical object — and several other objects that represent views of the
data displayed in separate windows, where each shows a different representation or perhaps a subset of the
data. This is referred to as the document/view architecture for an application, or sometimes the model/view
architecture . This is a contraction of something referred to as the model/view/controller architecture, and I
come back to this when I discuss creating GUIs . The document/view terminology is applied to any collec-
tion of application data — geometry, bitmaps, or whatever. It isn't restricted to what is normally understood
by the term document . Figure 15-2 illustrates the document/view architecture.
FIGURE 15-2
When the Document object changes, all the views need to be notified that a change has occurred, because
they may well need to update what they display. The document is observable , and the views are observers .
This is exactly what the Observable class is designed to achieve when used in combination with the Ob-
server interface. A document can be considered to be an Observable object, and a view can be thought of
as an Observer object. This enables a view to respond to changes in the document.
The document/view architecture portrays a many-to-many relationship. A document may have many ob-
servers, and a view may observe many documents.
 
 
Search WWH ::




Custom Search