Decorating with Deadly Sins and Heavenly Virtues | 153
}
override public function evil( ):Number
{
return +/-00 + components.evil( );
}
Examples 4-22 through 4-35 make up the seven deadly (revised) sins and seven heav-
enly (revised) virtues. However, what they really represent is the flexibility of the
Decorator design pattern. (Also, they illustrate the complex issue of saving souls.)
The Good and Evil Concrete Decorators
Following are 14 concrete decorator classes. They’re all the same except for the
names and values assigned to the numeric properties. It’s a lot easier just to do one,
and then paste it into a new ActionScript file and edit in changes rather than doing
them all from scratch. Once you’ve completed all 14, go ahead and add two
more—good and evil concrete decorators of your own making. In Examples 4-22
through 4-35, the filename is in the caption.
Heavenly virtues
Example 4-22. Integrity.as
package
{
public class Integrity extends Decorator
{
private var components:Component;
public function Integrity(components:Component) {
this.components=components;
}
override public function getSoul( ):String
{
return components.getSoul( ) + "|Integrity";
}
override public function good( ):Number
{
return 14 + components.good( );
}
override public function evil( ):Number
{
return -6 + components.evil( );
}
}
}