Home arrow Flash arrow Using Concrete Decorator Classes
FLASH

Using Concrete Decorator Classes


In this fifth part of a six-part series on the decorator pattern, we create a whimsical example involving good and evil to show you concrete decorators in action. 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 / 4
December 24, 2008
TABLE OF CONTENTS:
  1. · Using Concrete Decorator Classes
  2. · Deadly sins
  3. · Implementing the Good and Evil Decorator
  4. · Charting souls

print this article
SEARCH DEVARTICLES

Using Concrete Decorator Classes
(Page 1 of 4 )

The Good and Evil Concrete Decorators

Following are 14 concrete decorator classes. They’re all the same except for the names and values assigned to the numeric properties. It’s a lot easier just to do one, and then paste it into a new ActionScript file and edit in changes rather than doing them all from scratch. Once you’ve completed all 14, go ahead and add two more—good and evil concrete decorators of your own making. In Examples 4-22 through 4-35, the filename is in the caption.

Heavenly virtues

Example 4-22. Integrity.as

package
{
   public class Integrity extends Decorator
   {
     
private var components:Component;
      public function Integrity(components:Component) { 
         
this.components=components;
      }
      override public function getSoul():String
      {
        
return components.getSoul() + "|Integrity";
      }
      override public function good():Number
      {
        
return 14 + components.good();
      }
      override public function evil():Number
      {
        
return -6 + components.evil();
      }
   }
}

Example 4-23. Hope.as

package
{
   public class Hope extends Decorator
   {
     
private var components:Component;
      public function Hope(components:Component)
      {
        
this.components=components;
      }
      override public function getSoul():String
      {
        
return components.getSoul() + "|Hope";
      }
      override public function good():Number
      {
        
return 5 + components.good();
      }
      override public function evil():Number
      {
        
return -10 + components.evil();
      }
   }
}

Example 4-24. Courage.as

package
{
   public class Courage extends Decorator
   {
     
private var components:Component;
      public function Courage(components:Component)
      {
        
this.components=components;
      }
      override public function getSoul():String
     
{
        
return components.getSoul() + "|Courage";
      }
      override public function good():Number
      {
        
return 10 + components.good();
      }
      override public function evil():Number
      {
        
return -8 + components.evil();
      }
   }
}

Example 4-25. Compassion.as

package
{
   public class Compassion extends Decorator
   {
     
private var components:Component;
      public function Compassion(components:Component)
      {
        
this.components=components;
      }
      override public function getSoul():String
      {
        
return components.getSoul() + "|Compassion";
      }
      override public function good():Number
      {
        
return 7 + components.good();
      }
      override public function evil():Number
      {
        
return -15 + components.evil();
      }
   }
}

Example 4-26. Openness.as

package
{
   public class Openness extends Decorator
   {
     
private var components:Component;
      public function Openness(components:Component)
      {
        
this.components=components;
      }
      override public function getSoul():String
      {
        
return components.getSoul() + "|Openness";
      }
      override public function good():Number
      {
        
return 12 + components.good();
      }
      override public function evil():Number
      {
        
return -15 + components.evil();
      }
   }
}

Example 4-27. Diligence.as

package
{
   public class Diligence extends Decorator
   {
     
private var components:Component;
      public function Diligence(components:Component)
      {
        
this.components=components;
      }
      override public function getSoul():String
      {
        
return components.getSoul() + "|Diligence";
      }
      override public function good():Number
      {
        
return 10 + components.good();
      }
      override public function evil():Number
      {
        
return -5 + components.evil();
      }
   }
}

Example 4-28. Justice.as

package
{
   public class Justice extends Decorator
   {
     
private var components:Component;
      public function Justice(components:Component)
      {
        
this.components=components;
      }
      override public function getSoul():String
      {
        
return components.getSoul() + "|Justice";
      }
      override public function good():Number
      {
        
return 9 + components.good();
      }
      override public function evil():Number
      {
        
return -9 + components.evil();
      }
   }
}


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