ActionScript 3.0 Design Patterns

(Chris Devlin) #1

166 | Chapter 4: Decorator Pattern


As with all Decorator design patterns, all other classes are derived from this abstract


component class. In the next section, you’ll see that all of the concrete component


classes are subclasses of theAuto class.


Hybrid car classes concrete component


The four hybrid autos are placed into separate concrete component classes that are all


subclassed from the Auto class. The constructor function assigns a value to the


informationproperty, and theprice( )function returns a value representing the car’s


price. In Examples 4-39 to 4-42, the captions are the filenames to use for saving each


class.


Example 4-39. Prius.as


package
{
public class Prius extends Auto
{
public function Prius( )
{
information = "Toyota Prius Hybrid~\n";
}
override public function price( ):Number
{
return 21725.00;
}
}
}


Example 4-40. Mariner.as


package
{
public class Mariner extends Auto
{
public function Mariner( )
{
information = "Mercury Mariner Hybrid~\n";
}
override public function price( ):Number
{
return 29225.00;
}
}
}


Example 4-41. Accord.as


package
{
public class Accord extends Auto
{

Free download pdf