ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Your Application Plan: It Ain’t You Babe | 61

Choosing the Right Design Pattern


Choosing the best design pattern for a particular situation is as much an art as it is a


formula. Throughout the book, you’ll see that we’ve included a wide variety of


examples, and you may even see a few similar examples with different design pat-


terns. The reason is that most development challenges can be approached from more


than a single angle. From one angle, a solution seems good and natural, but from a


different angle, another solution seems better. For example, a major project employ-


ing a design pattern involved a video player that would be able to play, record, stop,


and pause a video using Flash Media Server 2. The solution originally seemed to lie


in state machine because of a related project. The “fit” between what needed to be


done and the concepts in a state machine seemed to be perfect. From there it was a


simple step to the State design pattern. It was tested as a solution, and it worked so


well, and had the required flexibility, that it was adopted as the right solution.


As you go through the examples in the book, you’ll see that the patterns have been


organized into three parts: creational, structural, and behavioral. The parts in the


book describe the general categories for the design patterns. The chapters within the


parts explain how to create the designs in ActionScript 3.0, and give examples and


explanations of their actual use.


In addition to organizing the design patterns into the purposes for which the pat-


terns are designed, the Gang of Four also classified the patterns byscope. Scope


refers to whether the pattern applies primarily to object or class. In selecting the


design patterns for this book, we selected representative patterns from each of the


matrices that these class and object classifications represent. Table 1-1 shows the


design patterns chosen for this book organized by purpose and scope.


Achieving Better OOP Through Design Patterns


While this chapter has provided an introduction to key OOP concepts for those who


are relatively new to OOP, learning the design patterns should prove useful in learn-


ing OOP as well. We might even venture to add that if this is your initial


Table 1-1. Design pattern classifications


Purpose
Creational Structural Behavioral
Class Factory Method Adapter (class) Template
Method
Scope
Object Singleton Adapter (object) Command
Composite Observer
Decorator State
Strategy
Free download pdf