ActionScript 3.0 Design Patterns

(Chris Devlin) #1

138 | Chapter 4: Decorator Pattern


public function DecConA(components:Component)
{
this.components=components;
}

Finally, you need a getter function to get theuniqueinformation from the concrete


decorator. The public method inherited from theDecoratorclass must be set up


using theoverridestatement. Here, the method gets both the concrete component’s


information [components.getInformation( )],and adds on that of the concrete deco-


ration [+ " Decoration Alpha:"]:


override public function getInformation( ):String
{
return components.getInformation( ) + " Decoration Alpha:";
}

Concrete Decorations


Now, we’re all set to write the concrete decorator classes. Save Examples 4-4 and 4-5


asDecConA.as andDecConB.as, respectively.


In several of the decorator classes, you’ll see:
this.components = components;
Such code is a non-standard use of thethisidentifier, but it makes
sense in this context because it differentiates the variable and parame-
ter. Normally, you wouldn’t use thethisidentifier in this manner. The
variable and parameter names are identical to emphasize the use of the
abstract class in both cases, with one passing the value to the other.

Example 4-4. DecConA.as


package
{
//Concrete Decorator "Alpha"
public class DecConA extends Decorator
{
private var components:Component;
public function DecConA(components:Component)
{
this.components=components;
}
override public function getInformation( ):String
{
return components.getInformation( ) + " Decoration Alpha:";
}
}
}

Free download pdf