Home arrow Flash arrow Page 3 - A Simple Decorator Pattern Example
FLASH

A Simple Decorator Pattern Example


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.

Author Info:
By: O'Reilly Media
Rating: 4 stars4 stars4 stars4 stars4 stars / 9
December 04, 2008
TABLE OF CONTENTS:
  1. · A Simple Decorator Pattern Example
  2. · Abstract Decorator Class
  3. · Concrete Decorations
  4. · Wrapping Up

print this article
SEARCH DEVARTICLES

A Simple Decorator Pattern Example - Concrete Decorations
(Page 3 of 4 )

Now, we’re all set to write the concrete decorator classes. Save Examples 4-4 and 4-5 as DecConA.as and DecConB.as, respectively.

In several of the decorator classes, you’ll see:

  this.components = components;

Such code is a non-standard use of thethisidentifier, but it makes sense in this context because it differentiates the variable and parameter. Normally, you wouldn’t use thethisidentifier in this manner. The variable and parameter names are identical to emphasize the use of the abstract class in both cases, with one passing the value to the other.

Example 4-4. DecConA.as

package
{
   //Concrete Decorator "Alpha"
   public class DecConA extends Decorator
   {
     
private var components:Component;
      public function DecConA(components:Component)
      {
        
this.components=components;
      }
      override public function getInformation():String
      {
        
return components.getInformation() + " Decoration Alpha:";
      }
   }
}

Example 4-5. DecConB.as

package
{
   //Concrete Decorator "Beta"
   public class DecConB extends Decorator
   {
     
var components:Component;
      public function DecConB(components:Component) {
         
this.components=components;
      }
      override public function getInformation():String
      { 
         
return components.getInformation() + " Decoration Beta:";
      }
   }
}


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