A Simple Decorator Pattern Example - Concrete Decorations
(Page 3 of 4 )
Now, we’re all set to write the concrete decorator classes. Save Examples 4-4 and 4-5 as DecConA.as and DecConB.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 parameter. 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:";
}
}
}
Example 4-5. DecConB.as
package
{
//Concrete Decorator "Beta"
public class DecConB extends Decorator
{
var components:Component;
public function DecConB(components:Component) {
this.components=components;
}
override public function getInformation():String
{
return components.getInformation() + " Decoration Beta:";
}
}
}
Next: Wrapping Up >>
More Flash Articles
More By O'Reilly Media
|
This article is excerpted from chapter four of ActionScript 3.0 Design Patterns Object Oriented Programming Techniques, written by William B. Sanders and Chandima Cumaranatunge (O'Reilly, 2007 ISBN: 0596528469). Check it out today at your favorite bookstore. Buy this book now.
|
|