Delving More Deeply into the Decorator Pattern
(Page 1 of 4 )
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.
Decorating with Deadly Sins and Heavenly Virtues
Action gaming pits different kinds of heroes and villains against one another, and the combatants have different weapons and shields. That is, they’re decorated with different characteristics and abilities. In order to see how to add some more functions to a Decorator pattern, what could be more appropriate than pitting good against evil?
Table 4-1 shows a list of deadly sins and heavenly virtues. (The list is considerably updated from Dante’s Inferno and Prudentius’ epic poem, Psychomachia, both of whom I understand were using Commodore-64’s to make their lists.)
Table 4-1. Decorations of good and evil
| Deadly Sin | Description | Virtue | Description |
|---|
| Rage | Uncontrolled anger—striking out at syntax errors | Compassion | Caring about others—Helping procedural programmers transition to OOP |
| Malice | Meanness, malevolence, ill will, cruelty, and hatred toward others–unkind remarks about Linux. | Courage | Doing the right thing regardless of the danger—taking on object-oriented programming |
| Obfuscation | Hiding the truth— redefining an act, knowledge by adding confusion—coding without comments | Hope | Belief in eventual success of good over evil—you really can complete the project on time |
| Arrogance | Excessive pride, not considering others’ beliefs, feelings, or knowledge—belief that Microsoft Windows is the only real OS | Justice | A fair balance and even chance—using Windows, Mac OS, and Linux |
| Prejudice | Judging others on the basis of stereotypes and not their actions—teasing Mac users | Openness | Capacity to consider new knowledge, ideas, and contrary ideas—writing a program on a Mac |
| Dogmatisms | Narrow, inflexible belief even in light of evidence to the contrary—continue to use procedural programming methods | Integrity | Maintaining values even when tempted to abandon them for short term gains—foregoing hacks even though they’d get the job done and the client would never know |
| Indifference | Seeing suffering and doing nothing or not even caring to help—unwilling to offer help in learning OOP | Diligence | Willingness to stick with an especially difficult task to complete it—learning design patterns |
Thinking about what has been presented so far in this chapter, the first thing that comes to mind is a property that describes each of the deadly sins and heavenly virtues. That’s easy enough, because just like the paper doll example, all we have to do is to assign a property value to each decorator. However, we can do more with the Decorator design pattern, as you’ll see in the next two sections.
Next: Adding Properties and Methods >>
More Flash Articles
More By O'Reilly Media
|
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). Check it out today at your favorite bookstore. Buy this book now.
|
|