Home arrow Flash arrow Page 2 - Using the Decorator Pattern for a Real Web Site
FLASH

Using the Decorator Pattern for a Real Web Site


In this conclusion to a six-part series on the decorator pattern, we're going to put what we've learned to work on a more realistic example than the ones we've covered up until now: a web site for a hybrid car dealership. 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: 5 stars5 stars5 stars5 stars5 stars / 5
December 31, 2008
TABLE OF CONTENTS:
  1. · Using the Decorator Pattern for a Real Web Site
  2. · Hybrid car classes concrete component
  3. · Using Auto Options as Decorators
  4. · Setting Up the User Interface
  5. · Creating the document and setting the stage
  6. · Implementing the concrete components and their decorators

print this article
SEARCH DEVARTICLES

Using the Decorator Pattern for a Real Web Site - Hybrid car classes concrete component
(Page 2 of 6 )

The four hybrid autos are placed into separate concrete component classes that are all subclassed from the Auto class. The constructor function assigns a value to the information property, and the price() function returns a value representing the carís price. In Examples 4-39 to 4-42, the captions are the filenames to use for saving each class.

Example 4-39. Prius.as

package
{
   public class Prius extends Auto
   {
     
public function Prius()
      {
        
information = "Toyota Prius Hybrid~\n";
      }
      override public function price():Number
      {
        
return 21725.00;
      }
   }
}

Example 4-40. Mariner.as

package
{
   public class Mariner extends Auto
   {
     
public function Mariner()
      {
        
information = "Mercury Mariner Hybrid~\n";
      }
      override public function price():Number
      {
        
return 29225.00;
      }
   }
}

Example 4-41. Accord.as

package
{
   public class Accord extends Auto
   {
     
public function Accord()
      {
        
information = "Accord Hybrid~\n";
      }
      override public function price():Number
      {
        
return 30990.00;
      }
   }
}

Example 4-42. Escape.as

package
{
   public class Escape extends Auto
   {
     
public function Escape()
      {
        
information = "Ford Escape Hybrid\n~";
      }
      override public function price():Number
      {
        
return 26240.00;
      }
   }
}

The prices here are based on prices found on the Internet, but they may or may not reflect prices at a later date. If you want to update prices or even use different autos, feel free to do so.

The\nescape character and the tilde (~) characters are used for formatting purposes. The\nis a line break, and the tilde (~) helps in separating out all the different models that become a big string as the decorator merges them altogether. Without these, the output would be a mess.


blog comments powered by Disqus
FLASH ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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