Applying a Simple Decorator Pattern in Flash: Paper Doll | 145
All si xdecorations can be used in any combination you want with the instance of the
Modelclass. This next section shows how to implement the Decorator pattern using
the different decorators.
Implementing the Paper Doll Decorator
As noted, no interface was created for implementing this application, and so you can
see clearly how the concrete component is wrapped by the decorators. Then, on the
stage, you can see the effects of the different combinations.
The sequence is:
- Instantiate a concrete component.
- Wrap the concrete component in the desired decorator instance using the format:
componentInstance = new DecoratorInstance(componentInstance) - Apply the getter method (getDressed( )) to the concrete component instance
initiated to get the fully wrapped values. The values will include those of the
concrete component instance and the applied decorations.
Example 4-16 illustrates how to implement the paper doll decorator.
Example 4-15. Muff.as
package
{
public class Muff extends Dresser
{
private var model:Model;
public function Muff(model:Model)
{
this.model=model;
}
override public function getDressed( ):String
{
return model.getDressed( ) + "~muff";
}
}
}
Example 4-16. FashionShow.as
package
{
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Sprite;
public class FashionShow extends Sprite
{
var ensemble:Array=new Array( );
public function FashionShow( )
{