Flash
  Home arrow Flash arrow A Simple Decorator Pattern Example
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

A Simple Decorator Pattern Example
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-12-04

    Table of Contents:
  • A Simple Decorator Pattern Example
  • Abstract Decorator Class
  • Concrete Decorations
  • Wrapping Up

  • 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


    A Simple Decorator Pattern Example


    (Page 1 of 4 )

    In this second part of a six-part series on the Decorator design pattern, you will walk through an example that shows you the minimum number of components required to create it. 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.

    Minimalist Abstract Decorator

    To get started with the Decorator design pattern, a minimum implementation needs the following:

    1. An abstract component
    2. An abstract decorator
    3. A concrete component
    4. Concrete decorators

    For the sake of clarity, two decorators will be devised so that you can better see how the structure works (and it’s closer to the model shown in Figure 4-1.) Of all the classes devised in this pattern, by far the most important is the initial abstract class modeling the component. Every other class is subclassed from this initial class.

    Abstract Component Class

    To begin the process of creating a Decorator design pattern, create a component. You might think of a component as an undecorated Christmas tree, or even a person deciding what to wear. It’s simple because all the added features are handled by decorators. Example 4-1 has only a single string variable that will be used to describe the component. Save the script as Component.as.

    Example 4-1. Component.as

    package
    {
      
    //Abstract Component in Decorator Design Pattern
      
    //**************
      
    //Abstract class
      
    public class Component
      
    {
         
    internal var information:String;

          public function getInformation():String
          {
             return information;
          }
       }
    }

    From this point on, all the classes will extend the Component class. Keeping in mind that the class is an abstract one—or at least is treated as one—its primary function is to establish a basic structure for the rest of the application. It contains a single variable,information, and a single getter function,getInformation(). These elements set up both the concrete components and decorations. Both components and decorations need to display information about their characteristics. A concrete Christmas tree displays information that lets you know that it’s a Christmas tree instead of another kind of object that can be decorated, such as a front yard to be decorated with gnomes and pink plastic flamingoes. Additionally, you want to be able to retrieve information, and so it has a getter function.

    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