
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
362
|
Chapter 16: The Observer Design Pattern
Now let’s move on to OutputPanelView, a class that receives LogMessage instances
from Logger and generates corresponding on-screen messages.
The OutputPanelView Class
The OutputPanelView class displays log messages in the Output panel in Flash’s Test
Movie mode. It implements the Observer interface from Example 16-2 and defines
only one property and one method:
log
An instance property that stores a reference to the Logger instance being
observed
update( )
The all-important method used by Logger to broadcast messages to the
OutputPanelView instance
By convention, all observer classes should store an instance of the subject they are
observing. They use that reference to pull changes from the subject or to set the sub-
ject’s state. In our case, the Logger class broadcasts its updates using the push model,
so the
log property in OutputPanelView is not actually used. However, we maintain
it as a matter of good form and for the sake of possible future updates to the
OutputPanelView class.
Example 16-4 shows the source code for the OutputPanelView class. Pay special
attention to the update( ) method, which receives a LogMessage instance as an argu-
ment and uses it to display log messages in the Output panel. Notice that the generic
infoObj instance