ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Dynamic Selection of Concrete Components and Decorations: A Hybrid Car Dealership | 167

The prices here are based on prices found on the Internet, but they may or may not


reflect prices at a later date. If you want to update prices or even use different autos,


feel free to do so.


The\nescape character and the tilde (~) characters are used for formatting pur-


poses. The\nis a line break, and the tilde (~) helps in separating out all the different


models that become a big string as the decorator merges them altogether. Without


these, the output would be a mess.


Using Auto Options as Decorators


With all the concrete components in place, the next step will be to construct the dec-


orator class and the concrete decorators. Like the components they decorate, they


too will need an identification and price property as well as methods to return them.


The abstract decorator will set that up so that the derived classes have the necessary


properties and methods.


The options abstract decorator


As you have seen with other abstract decorator classes in this chapter, it’s one of the


simplest classes. Because it extends the abstract concrete component class, it inherits


all the class’ properties. However, we need to re-implement the getter function so that


public function Accord( )
{
information = "Accord Hybrid~\n";
}
override public function price( ):Number
{
return 30990.00;
}
}
}


Example 4-42. Escape.as


package
{
public class Escape extends Auto
{
public function Escape( )
{
information = "Ford Escape Hybrid\n~";
}
override public function price( ):Number
{
return 26240.00;
}
}
}


Example 4-41. Accord.as (continued)

Free download pdf