Decorating with Deadly Sins and Heavenly Virtues | 151
Decorating with Multiple Properties
Multiple properties and methods are not difficult to add to components, and the
same is true for decorator classes. Instead of a single property and method, you do
essentially the same thing using multiple methods and classes. Example 4-20 shows
the abstractDecoratorclass, subclassed from theComponentclass. Save the script as
Decorator.as.
As a subclass of theComponentclass, thisDecoratorabstract class does nothing more
than re-implement the getter functions—one returning a string, and the other two
returning a number. The properties that are to be returned were originally defined as
properties in theComponentclass, and as a subclass ofComponent, theDecoratorclass
doesn’t have to re-implement them. However, as you’ve seen in previous examples,
the getter functions are re-implemented. The only difference is that there are more of
them. However, the process and logic are the same.
Multiple Method Concrete Decorations
When it comes to the concrete decorations in this example application, we’re going
to see something slightly new. First, take a look at example 4-21. It’s a generic exam-
ple and shouldnotbe placed in as actual code. Just look at it. Several actual concrete
elements with working code will replace generic values.
Example 4-20. Decorator.as
package
{
//Abstract class
public class Decorator extends Component
{
override public function getSoul( ):String
{
return soul;
}
override public function good( ):Number
{
return goodness;
}
override public function evil( ):Number
{
return vice;
}
}
}