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

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

Delving More Deeply into the Decorator Pattern - Adding Properties and Methods
(Page 2 of 4 )

Up to now, weíve used a single string variable with a single getter method for the basic abstract component class. However, like any other class, this basic structure can accommodate more than a single variable or function. Example 4-17 shows three variables and getter functions. Save the script asComponent.as.

Example 4-17. Component.as

   //Abstract class
   public class Component
protected var soul:String="All that is inside a spirit";
      protected var goodness:Number;
      protected var vice:Number;

      public function getSoul():String
return soul;
      public function good():Number
return goodness;
      public function evil():Number
return vice;

Like the previous examples, we begin with a string property,soul. (Itís assigned a string literal, but thatís really not necessary because itís an abstract class and will never be seen or usedójust a clarification.) Next, two numeric properties are defined,goodnessandvice. These two properties will collect all the accumulated good and evil in a soul.

Next, three getter functions are supplied to get the values of the string and two numeric variables. Now the abstract component class is all set to go.

blog comments powered by Disqus

- 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 

Developer Shed Affiliates


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