Adding More Concrete Strategies and Concrete Contexts | 407
Notice that each clown can perform only a single trick and a single skit. We’ll have
to reconsider how to set up our strategies, or see if we can find a way to dynamically
add features later. For now, though, the clowns can choose only a single trick or skit.
The Trick Interface and Implementations
All the algorithms for doing tricks are encapsulated in the concrete strategy sub-
classes. TheTricksinterface (Example 11-9) provides the abstract method, and the
subclasses add detail to the operations. A total of three trick algorithms (Examples
11-10, 11-11, and 11-12) are implemented.
skits.skit( );
}
}
}
Example 11-7. Koka.as
package
{
class Koka extends Clown
{
public function Koka( )
{
tricks = new Disappear( );
skits = new Chase( );
}
}
}
Example 11-8. Bojo.as
package
{
class Bojo extends Clown
{
public function Bojo( )
{
tricks = new BaloonAnimals( );
skits = new FallDown( );
}
}
}
Example 11-9. Tricks.as
package
{
Example 11-6. Clown.as (continued)