O'Reilly logo

ActionScript 3.0 Design Patterns by Chandima Cumaranatunge, William Sanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding More Concrete Strategies and Concrete Contexts

The purpose of the minimalist example is to expose a design pattern's structure. However, with the Strategy pattern, a more robust example may actually do a better job of showing the pattern's features, because it places the pattern in a more practical context in the bare bones example.

In this next example, we envision a Strategy pattern used with a clown employment agency. The agency has a number of clowns it represents. Clients call for different clown venues—circuses, birthday parties, political conventions. They want either a particular clown or particular clown acts (skits) or tricks they can perform. To create a flexible program for the clown agency, each of the skits and tricks has been created in separate algorithms. The algorithms are encapsulated, and the clown characters delegate their performance skills to the encapsulated algorithms—strategies.

The Clowns

The first step is to create a context class and concrete contexts that will use the different tricks and skits. Example 11-6 is the main context class establishing the references to the strategy methods. The trick and skit operations are delegated to the strategy classes. Then Example 11-7 and Example 11-8 create two concrete clowns. Each is assigned a different trick and skit that are delegated to concrete strategy instances. To get started, open three ActionScript files and enter the code in Example 11-6 to Example 11-8, saving each with the caption name provided. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required