Delving More Deeply into the Decorator Pattern (Page 1 of 4 )
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
Uncontrolled anger—striking out at syntax errors
Caring about others—Helping procedural programmers transition to OOP
Meanness, malevolence, ill will, cruelty, and hatred toward others–unkind remarks about Linux.
Doing the right thing regardless of the danger—taking on object-oriented programming
Hiding the truth— redefining an act, knowledge by adding confusion—coding without comments
Belief in eventual success of good over evil—you really can complete the project on time
Excessive pride, not considering others’ beliefs, feelings, or knowledge—belief that Microsoft Windows is the only real OS
A fair balance and even chance—using Windows, Mac OS, and Linux
Judging others on the basis of stereotypes and not their actions—teasing Mac users
Capacity to consider new knowledge, ideas, and contrary ideas—writing a program on a Mac
Narrow, inflexible belief even in light of evidence to the contrary—continue to use procedural programming methods
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
Seeing suffering and doing nothing or not even caring to help—unwilling to offer help in learning OOP
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.