Flash
  Home arrow Flash arrow Page 2 - The Decorator Pattern in Action
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

The Decorator Pattern in Action
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-12-11

    Table of Contents:
  • The Decorator Pattern in Action
  • Decorator Class: Dressing the Dolls
  • Concrete decorator classes
  • Implementing the Paper Doll Decorator

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Decorator Pattern in Action - Decorator Class: Dressing the Dolls


    (Page 2 of 4 )

    Example 4-8 is the abstract Decorator class, Dresser, which extends the component class, Model. The major contribution here is simply re-implementing thegetDressed()method with a reference to the inheritedwhatToWearproperty.

    Example 4-8. Dresser.as

    package
    {
       //Abstract class
       public class Dresser extends Model
       {
         
    override public function getDressed():String
          {
             return whatToWear;
          }
       }
    }

    All of the concrete decorators will be subclassed for this class.

    The Concrete Classes

    Once the two main abstract classes in the Decorator pattern have been established, you’re all set to create the concrete ones. In the previous minimalist Decorator example, you saw the output using the trace() statement. Instead of trace() statements, both the concrete component and decorators need to be formatted for later parsing, so a tilde character (~) has been added as a demarcation point. Because all the strings from both the concrete component and decorators are grouped together into a single large string, the tilde serves as cutting point.

    Concrete component class

    The concrete component class is the only concrete class that extends directly from the abstract concrete class. All the other classes in this application extend from the abstract decorator class. Using a simple constructor function, Sue(), the class assigns a value to the whatToWear variable. This is enough to identify the class as an instance of the main abstract component class,Model, and to establish a unique name. All decorations use the concrete component as the target for the decorations. Save Example 4-9 asSue.as.

    Example 4-9. Sue.as

    package
    {
       public class Sue extends Model
       {
         
    public function Sue() 
          {
             whatToWear="~sue";
          }
       }
    }

    If you want to create more concrete component classes, all you need to do is create a similar class with a different name and value for thewhatToWear variable. With this structure, you have no limit to the number of new concrete components you can add.

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "ActionScript 3.0 Design Patterns Object...
     

    Buy this book now. 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.

    FLASH ARTICLES

    - 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
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek