ActionScript 3.0 Design Patterns

(Chris Devlin) #1

150 | Chapter 4: Decorator Pattern


Examples 4-18 and 4-19 provide the concrete components forDickandJaneclasses.


Each class just needs a string value forsouland numeric values forgoodnessand


vice—all inherited properties from theComponentclass. Save Example 4-18 asDick.as,


and Example 4-19 asJane.as.


These concrete component classes are exactly like the previous examples we’ve


examined, except we have two instead of one. Furthermore, instead of using a single


string variable, two additional numeric variables are added, along with their assigned


values. Otherwise, they’re just the same.


In these two concrete classes, the properties are inherited directly from the abstract


Component class. No overrides or other special adjustments are needed. This is


because theDickandJaneclasses are components, both to be decorated by the deco-


rator classes. The overrides that generate unique methods and characteristics for the


concrete decorators are accomplishedby the decorator classes. Therefore, overrides


by the concrete component classes are unnecessary.


Example 4-18. Dick.as


package
{
public class Dick extends Component
{
public function Dick( )
{
soul = "Dick's soul\n";
goodness=0;
vice=0;
}
}
}


Example 4-19. Jane.as


package
{
public class Jane extends Component
{
public function Jane( )
{
soul = "Jane's soul\n";
goodness=0;
vice=0;
}
}
}

Free download pdf