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-5as DecConA.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 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:"; } } }