Chapter 11. Strategy Pattern

Enact strategy broadly, correctly and openly. Then you will come to think of things in a wide sense and, taking the void as the Way, you will see the Way as void.

Miyamoto Musashi (16th-17th Century Japanese developer of Sword Method Design Pattern [Kenjutsu] and guy who reminds us that in ActionScript 3.0 the void statement is all lowercase.)

All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved.

Sun Tzu

However beautiful the strategy, you should occasionally look at the results.

Winston Churchill (Remark made after finishing up a “Hello world” application using the Strategy pattern.)

What is the Strategy Pattern?

The Strategy design pattern is sometimes used to illustrate good OOP practices rather than offered as a design pattern that has focused applications. In one article [Agerbo and Cornils, 98], the authors set up a number of guidelines for judging design patterns. One guideline posits that a design pattern should not be an inherent object-oriented way of thinking. Then they proceed to reject the Strategy design pattern because it seems to be nothing but a collection of fundamental OOP principles!

Whether the Strategy pattern is a true design pattern or just a template for how to go about OOP programming, it has lots to offer. Because the class model looks identical to the State design pattern, we need to spend some time distinguishing the Strategy from the State pattern to show not only ...

Get ActionScript 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.