Take a Design Pattern to Work Part IV: Establishing a Design Pattern Foundation
Gentle Reader: This is Part 4 of a four-part series of posts on introducing design patterns and OOP into the work place. Parts 1 through 3 will provide the context for this part. Also, taking a look at No Time for OOP and Design Patterns will give you the background on this series. As always, we invite your comments.
Note: Chandima wrote the chapter in our book on the Factory Method, and he gave me invaluable help on the main program in this post as well.
Recap
Up to this point we’ve examined a simple program that loads external text and graphics, a common ActionScript chore. In the most general terms, this is where we’ve been:
- Part I: Identifying the problem in a current solution. Why ActionScript on the Timeline can cause problems.
- Part II: Providing a simple OOP solution: Use of Inheritance
- Part III: Loosening Up a programs structure: Adding a design pattern element —a simple factory
To conclude the process, we now come to the last part—introducing an actual design pattern to the work place.
- Part IV: Establishing a Design Pattern Foundation.
Given the preceding steps, the context is now in place to add a full design pattern.
From Part to Whole
Part III introduced the Simple Factory method inserted into an existing OOP program. Now it’s time to step back and look at a design pattern en toto and instead of incrementally adding to the existing program, we will refactor the whole kit-n-kaboodle from the perspective of a design pattern.
To get started, if you’re not familiar with the Factory Method pattern, take a look at Chapter 2. In fact Chandima’s Sprite Factory example beginning on page 84 is one of the clearest and most appropriate examples that you can find of the Factory Method pattern in ActionScript 3.0. So before continuing, you might want to do a quick review of the Factory Method and take a look at Figure 1, the class diagram for the pattern. (We’ll wait for you…).

Figure 1: Factory Method Design Pattern
As you can see, the Factory Method (simple factory) is part of the Creator interface and the ConcreteCreator. The interface is an abstract class; so at least one of the methods needs to be abstract—impossible to directly instantiate but easily overridden in a child class.
Read more…


Bill Sanders
Recent Comments