ActionScript 3.0 Design Patterns

(Chris Devlin) #1

148 | Chapter 4: Decorator Pattern


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’redecoratedwith dif-


ferent 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’sInfernoand Prudentius’ epic poem,Psychomachia, both of


whom I understand were using Commodore-64’s to make their lists.)


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


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


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 pro-
gramming
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—fore-
going 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 diffi-
cult task to complete it—learning design
patterns
Free download pdf