Home arrow Flash arrow Page 3 - Delving More Deeply into the Decorator Pattern
FLASH

Delving More Deeply into the Decorator Pattern


In this fourth part of a six-part series on the decorator pattern, we use deadly sins and heavenly virtues to illustrate how to add properties and methods, and more. 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 / 6
December 18, 2008
TABLE OF CONTENTS:
  1. · Delving More Deeply into the Decorator Pattern
  2. · Adding Properties and Methods
  3. · Multiple Concrete Components
  4. · Decorating with Multiple Properties

print this article
SEARCH DEVARTICLES

Delving More Deeply into the Decorator Pattern - Multiple Concrete Components
(Page 3 of 4 )

We could look at one soul at a time, but what fun is that? More important, in a lot of applications, having a single component to decorate isn’t too useful either. So instead of having a single soul to decorate, we’ll add two. For the time being, we’ll forego any debates about original sin and start our souls with a clean slate. Both goodness and vice will be set to zero. Just give them different soulvalues so they can be differentiated.

Examples 4-18 and 4-19 provide the concrete components for DickandJaneclasses. Each class just needs a string value forsouland numeric values forgoodnessandvice—all inherited properties from theComponentclass. Save Example 4-18 asDick.as, and Example4-19 asJane.as.

Example 4-18. Dick.as

package
{
   public class Dick extends Component
   {
     
public function Dick()
     
{
         soul = "Dick's soul\n";
         goodness=0;
         vice=0;
     
}
   }
}

Example 4-19. Jane.as

package
{
   public class Jane extends Component
   {
     
public function Jane()
     
{
         soul = "Jane's soul\n";
         goodness=0;
         vice=0;
     
}
   }
}

These concrete component classes are exactly like the previous examples we’ve examined, except we have two instead of one. Furthermore, instead of using a single string variable, two additional numeric variables are added, along with their assigned values. Otherwise, they’re just the same.

In these two concrete classes, the properties are inherited directly from the abstractComponentclass. No overrides or other special adjustments are needed. This is because theDickandJaneclasses are components, both to be decorated by the decorator classes. The overrides that generate unique methods and characteristics for the concrete decorators are accomplished by the decorator classes. Therefore, overrides by the concrete component classes are unnecessary.


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