320 | Chapter 8: Observer Pattern
In the concrete observer file, you may have noticed that two different interfaces were
implemented—ObserverandDataOut. The former implements theupdate( )function
that calls theoutToDesign( )function from theDataOutinterface. Also, instead of
void, theoutToDesign( )function returns an Array. Note that the array data is stored
in the variabledataNow and returned through theoutToDesign( ) method.
The Data Design Classes
The classes invoked for the three different data displays require close attention. Keep
in mind that the array for all three classes is the array that returns the value for the four
quarters. All three classes use the same array name,listArray, to help you remember
that the data are all coming from the same subject. The displays may be different, but
the data coming into each object through subscription as an observer is identical.
UIList component
TheUIListcomponent needs a copy placed in the Library of the Flash document file
(FLA file) that you’ll use to launch the application. So, before going on, open a new
Flash document file and save it asDoDesign.flain the same directory as the rest of
the files for this application. Once you have your document file open and saved, use
Example 8-24. ConcreteObserver.as
package
{
//Concrete Observer
class ConcreteObserver implements Observer,DataOut
{
private var dataNow:Array;
private var q1:Number,q2:Number,q3:Number,q4:Number;
public function ConcreteObserver( )
{
}
public function outToDesign( ):Array
{
return dataNow;
}
public function update(q1:Number,q2:Number,q3:Number,q4:
Number):void
{
this.q1=q1;
this.q2=q2;
this.q3=q3;
this.q4=q4;
dataNow=new Array(q1,q2,q3,q4);
outToDesign( );
}
}
}