Flash
  Home arrow Flash arrow Page 3 - Using the Decorator Pattern for a Real Web...
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

Using the Decorator Pattern for a Real Web Site
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-12-31

    Table of Contents:
  • Using the Decorator Pattern for a Real Web Site
  • Hybrid car classes concrete component
  • Using Auto Options as Decorators
  • Setting Up the User Interface
  • Creating the document and setting the stage
  • Implementing the concrete components and their decorators

  • 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


    Using the Decorator Pattern for a Real Web Site - Using Auto Options as Decorators


    (Page 3 of 6 )

    With all the concrete components in place, the next step will be to construct the decorator class and the concrete decorators. Like the components they decorate, they too will need an identification and price property as well as methods to return them. The abstract decorator will set that up so that the derived classes have the necessary properties and methods.

    The options abstract decorator

    As you have seen with other abstract decorator classes in this chapter, it’s one of the simplest classes. Because it extends the abstract concrete component class, it inherits all the class’ properties. However, we need to re-implement the getter function so that we can further reimplement it for the delegations the different concrete decorators use. Example 4-43 shows the abstract decorator class to be saved as Decorator.as.

    Example 4-43. Decorator.as

    package
    {
       //Abstract class
       public class Decorator extends Auto
       {
         
    override public function getInformation():String
          {
             return information;
          }
       }
    }

    Because theinformationvariable is inherited from the Auto class, we need not redefine it here. It represents an abstract string.

    The options concrete decorators

    The concrete decorators generate the information that adds the information property and price value to each option. As a concrete component is wrapped in each, the string data are added to any other strings that wrap the component. So, when the getInformation() method launches, it first gets the delegated information from all other options and the concrete component it wraps. In order not to get a huge string that we cannot unravel, a tilde (~) on the end of the added string will help separate all the different decorations. Examples 4-44 through 4-47 are labeled with the filenames used to save the class.

    Example 4-44. HeatedSeat.as

    package
    {
       public class HeatedSeats extends Decorator
       {
         
    private var auto:Auto;
          public function HeatedSeats(auto:Auto)
          {
            
    this.auto=auto;
          }
          override public function getInformation():String
          {
            
    return auto.getInformation() + " Heated Seats~";
          }
          override public function price():Number
          {
            
    return 350.78 + auto.price();
          }
       }
    }

    Example 4-45. GPS.as

    package
    {
       public class GPS extends Decorator
       {
         
    private var auto:Auto;
          public function GPS(auto:Auto)
          {
            
    this.auto=auto;
          }
          override public function getInformation():String
          {
            
    return auto.getInformation() +
               
    " Global Positioning System~";
          }
          override public function price():Number
          {
            
    return 345.88 + auto.price();
          }
       }
    }

    Example 4-46. RearViewVideo.as

    package
    {
       public class RearViewVideo extends Decorator
       {
         
    private var auto:Auto;
          public function RearViewVideo(auto:Auto)
          {
            
    this.auto=auto;
          }
          override public function getInformation():String
          {
            
    return auto.getInformation() + " Rear View Video~";
          }
          override public function price():Number
          {
            
    return 560.75 + auto.price();
          }
       }
    }

    Example 4-47. MP3.as

    package
    {
       public class MP3 extends Decorator
       {
         
    private var auto:Auto;
          public function MP3(auto:Auto)
          {
            
    this.auto=auto;
         
    }
          override public function getInformation():String
          {
            
    return auto.getInformation() + " MP3 Player~";
          }
          override public function price():Number
          {
            
    return 267.55 + auto.price();
          }
       }
    }

    For this particular application, we’re not concerned with separating the individual costs. In fact, we want each cost to be accumulated with the others, including the cost of the concrete component we’re decorating. So while the string value needs the tilde (~) for demarcation purposes, we don’t need it for the numeric value.

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek