Home arrow Flash arrow The Decorator Pattern in Action

The Decorator Pattern in Action

In this third part of a six-part series on the Decorator pattern, we move from last week's conceptual example to something more concrete: using the pattern to decorate a paper doll. 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). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 4 stars4 stars4 stars4 stars4 stars / 7
December 11, 2008
  1. · The Decorator Pattern in Action
  2. · Decorator Class: Dressing the Dolls
  3. · Concrete decorator classes
  4. · Implementing the Paper Doll Decorator

print this article

The Decorator Pattern in Action
(Page 1 of 4 )

Applying a Simple Decorator Pattern in Flash: Paper Doll

You can move from a conceptual example to a concrete one with a computerized paper doll game. The paper doll component is the doll being dressed, and the decorations are clothing items selected for the doll. Using ActionScript’s new Loader class, different GIF files are used to decorate a base GIF image of a Victorian paper doll. As in the previous abstract example, this example uses a single concrete component and several decorations.

This concrete example does not have an interface—keeping the focus on the application’s use of a Decorator pattern. However, it does have a graphic output so you can see the pattern’s ultimate output. (Later in this chapter, there’s an example with a full interface.)

Setting Up the Component Class

The first class is the component class, Model. From this, all other classes are subclasses. It’s very simple but key to the success of the application. As you can see, it’s very close to the previous abstract Decorator. It consists of a method, getDressed(), and a string variable,whatToWear,as shown in Example 4-7. Save the file asModel.as.

Example 4-7. Model.as

//Abstract class
public class Model
protected var whatToWear:String;
public function getDressed():String
return whatToWear;

Keep in mind that Example 4-7 should be treated as an abstract class. So the methodgetDressed()needs to be created as an override public function for it to work the way we want. However, the propertywhatToWear doesn’t need to be changed from its inherited characteristics.

blog comments powered by Disqus

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials