ActionScript 3.0 Design Patterns

(Chris Devlin) #1

318 | Chapter 8: Observer Pattern


To make the task more manageable and reusable, all the display outputs are orga-


nized into separate classes. We decided that the data would represent quarterly


reports, and so the application is set up to accept four numeric values, each repre-


senting quarterly values. Also, to make the whole process of outputting data more


manageable, we have introduced a third interface along with the Subject and


Observerinterfaces. This interface is set up so that it returns an array. The array will


contain the four numeric values representing the four quarters. To get started, open


up three ActionScript files, and copy the three files in Example 8-20, Example 8-21,


and Example 8-22 into each of the files. Save the interface files using the caption


names in the same folder.


Other than the newDataOutinterface, the other two are similar to those you’ve seen


elsewhere in this chapter. The four quarterly numeric values mentioned can be seen


in theObserver interface.


Example 8-20. Subject.as


package
{
//Subject Interface
public interface Subject
{
function subscribeObserver(o:Observer):void;
function unsubscribeObserver(o:Observer):void;
function notifyObserver( ):void;
}
}


Example 8-21. Observer.as


package
{
//Observer Interface
public interface Observer
{
function update(q1:Number,q2:Number,q3:Number,q4:Number):
void;
}
}


Example 8-22. DataOut.as


package
{
//Data Output Interface
public interface DataOut
{
function outToDesign( ):Array;
}
}

Free download pdf