168 | Chapter 4: Decorator Pattern
we can further reimplement it for the delegations the different concrete decorators use.
Example 4-43 shows the abstract decorator class to be saved asDecorator.as.
Because theinformationvariable is inherited from the Auto class, we need not rede-
fine it here. It represents an abstract string.
The options concrete decorators
The concrete decorators generate the information that adds theinformationprop-
erty and price value to each option. As a concrete component is wrapped in each, the
string data are added to any other strings that wrap the component. So, when the
getInformation( )method launches, it first gets the delegated information from all
other options and the concrete component it wraps. In order not to get a huge string
that we cannot unravel, a tilde (~) on the end of the added string will help separate
all the different decorations. Examples 4-44 through 4-47 are labeled with the filena-
mes used to save the class.
Example 4-43. Decorator.as
package
{
//Abstract class
public class Decorator extends Auto
{
override public function getInformation( ):String
{
return information;
}
}
}
Example 4-44. HeatedSeat.as
package
{
public class HeatedSeats extends Decorator
{
private var auto:Auto;
public function HeatedSeats(auto:Auto)
{
this.auto=auto;
}
override public function getInformation( ):String
{
return auto.getInformation( ) + " Heated Seats~";
}
override public function price( ):Number
{
return 350.78 + auto.price( );
}
}
}