Flash
  Home arrow Flash arrow Page 3 - 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 - Concrete decorator classes


    (Page 3 of 4 )

     

    Moving from the minimalist example previously shown in this chapter, it’s a little easier to see how the Decorator pattern works by actually seeing something happening in a graphic display. When the initial instance of the concrete component is created, all references in the concrete decorator class are to that instance. (See example 4-16, where the concrete component is wrapped in the decorators.) In all the concrete decorator classes, the reference to the model variable is a reference to the concrete component object. In this case, that’s the instance of the Sue() class, but it can be any instance of any concrete component. That’s why, if you wish to expand the application to include more concrete components (paper dolls to dress), you don’t have to make any fundamental changes. Just add another concrete component class. In Examples 4-10 to 4-15, the captions are the filenames.

    Example 4-10. OrangeDress.as

    package
    {
       public class OrangeDress extends Dresser
       {
         
    private var model:Model;
          public function OrangeDress(model:Model)
          {
            
    this.model=model;
          }
          override public function getDressed():String
          {
            
    return model.getDressed() + "~orangedress";
          }
       }
    }

    Example 4-11. BlueDress.as

    package
    {
       public class BlueDress extends Dresser
       {
         
    private var model:Model;
          public function BlueDress(model:Model)
          {
             this.model=model;
          }
          override public function getDressed():String
          {
            
    return model.getDressed() + "~bluedress";
          }
       }
    }

    Example 4-12. Bow.as

    package
    {
       public class Bow extends Dresser
       {
         
    private var model:Model;
          public function Bow(model:Model)
          {
            
    this.model=model;
          }
          override public function getDressed():String
          {
            
    return model.getDressed() + "~bow";
          }
       }
    }

    Example 4-13. Umbrella.as

    package
    {
       public class Umbrella extends Dresser
       {
         
    private var model:Model;
          public function Umbrella (model:Model)
          {
            
    this.model=model;
          }
          override public function getDressed():String
          {
            
    return model.getDressed() + "~ umbrella ";
          }
       }
    }

    Example 4-14. Hat.as

    package
    {
       public class Hat extends Dresser
       {
         
    private var model:Model;
          public function Hat(model:Model)
          {
            
    this.model=model;
          }
          override public function getDressed():String
          {
            
    return model.getDressed() + "~hat";
          }
       }
    }

    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";
          }
       }
    }

    All six decorations can be used in any combination you want with the instance of theModelclass. This next section shows how to implement the Decorator pattern using the different decorators.

    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 2 Hosted by Hostway
    Stay green...Green IT