410 | Chapter 11: Strategy Pattern
Even though we’ve discussed some possible shortcomings in this design, it still
shows how the strategies are built in the implementations of theTricksandSkits
classes. The final step is to see how to launch the program.
Here Come the Clowns!
For this example, theClownCollegeclass (Example 11-16) instantiates two different
clowns. Both clowns are typed asClowntypes following the dictum of programming
to the interface instead of the implementations; however, each instantiates through a
Clown subclass. Each is given a trick and skit, and it’s ready to run. Save
Example 11-16 using the caption name as the filename.
Once you’re finished saving Examples 11-6 through 11-16, open a new Flash docu-
ment and save it asClownCollege.fla. In the Document class window, type in
ClownCollegeand test the application. You should see the following in the Output
window:
* =>Koka<= *
Now you see it! Presto! It's gone!
Here I come! I'm going to get you!
Nah! Nah! Can't catch me!
* =>Bojo<= *
See! It's a doggy! No, it's not that!!
I'm climbing up this ladder!
Where's my banana peel?
Whoaaaa! I'm falling!!
Thanks for finding my banana peel!
Example 11-16. ClownCollege.as
package
{
import flash.display.Sprite;
public class ClownCollege extends Sprite
{
public function ClownCollege( )
{
var joker:Clown=new Koka( );
joker.doTrick( );
joker.doSkit( );
var gagGrrrl:Clown=new Bojo( );
gagGrrrl.doTrick( );
gagGrrrl.doSkit( );
}
}
}