
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Logger: A Complete Observer Example
|
377
Using the Logger Class
Now that we’ve seen how our subject (Logger) and its observers (OutputPanelView
and TextFieldView) work individually, let’s put them all together to form a func-
tional logging system. The code in this section could go on a frame in the timeline of
a .fla file or in a class (an .as file). Furthermore, the code works equally well with
public function debug(msg:String):Void {
if (logLevel >= Logger.DEBUG) {
lastMsg = new LogMessage(msg, Logger.DEBUG);
setChanged( );
notifyObservers(lastMsg);
}
}
// Wrapper methods for ObservableSubject methods follow. These methods
// subcontract their work out to the ObservableSubject instance, subj.
public function addObserver(o:Observer):Boolean {
return subj.addObserver(o);
}
public function removeObserver(o:Observer):Boolean {
return subj.removeObserver(o);
}
public function notifyObservers(infoObj:Object):Void {
subj.notifyObservers(infoObj);
}
public function clearObservers( ):Void {
subj.clearObservers( );
}
public function setChanged( ):Void {
subj.setChanged( );
}
public function clearChanged( ):Void {
subj.clearChanged( );
}
public function hasChanged( ):Boolean {
return subj.hasChanged( );
}
public function countObservers( ):Number {
return subj.countObservers( );
}