ActionScript 3.0 Design Patterns

(Chris Devlin) #1

36 | Chapter 1: Object-Oriented Programming, Design Patterns, and ActionScript 3.0


When you test the program, you’ll see the following:


Play Jimmie
Play Mozart
Play Willie
Play Coltrane

As you can see, it’s not rocket science and hardly cloaked in mystery. It’s just poly-


morphism. All instances were typed to the abstract classPolymorphism. Then they were


trace("Play Willie");
}
}
}


Example 1-30. Jazz.as


package
{
public class Jazz extends Polymorphism
{
override public function myMusic( ):void
{
trace("Play Coltrane");
}
}
}


Example 1-31. PlayMusic.as


package
{
import flash.display.Sprite;
public class PlayMusic extends Sprite
{
var rock:Polymorphism;
var classic:Polymorphism;
var country:Polymorphism;
var jazz:Polymorphism;


public function PlayMusic( ):void
{
rock=new Rock( );
rock.myMusic( );
classic=new Classic( );
classic.myMusic( );
country=new Country( );
country.myMusic( );
jazz=new Jazz( );
jazz.myMusic( );
}
}
}


Example 1-29. Country.as (continued)

Free download pdf