ActionScript 3.0 Design Patterns

(Chris Devlin) #1

346 | Chapter 9: Template Method Pattern


Not-So-Concrete Concrete Classes


The next step is to add a couple of concrete classes for selecting between video and


audio. First, both need to have some kind of selection, and rather than adding a real-


istic operation for selecting a video or audio file dynamically, both concrete classes


just add a literal. That’s pretty simple, but it illustrates the concept of adding neces-


sary details to the operations. Feel free to change the operation to accept dynamic


input. The play operations instantiate instances to play whatever names have been


placed in the string for the media file. Open up two more ActionScript files and add


Example 9-9 and Example 9-10 to the same folder as the abstract classes using the


caption names for the filenames.


Example 9-9. Vid.as


package
{
//A concrete class
//Vid class
public class Vid extends VidAudio
{
private var vidName:String;
override protected function selectMedia ( ):void
{
vidName="media";
}
override protected function playNow ( ):void
{
var playVideo=new PlayVideo(vidName);
this.addChild (playVideo);
}
}
}


Example 9-10. Audio.as


package
{
//A concrete class
//Audio Class
public class Audio extends VidAudio
{
private var tuneName:String;
override protected function selectMedia ( ):void
{
tuneName="iBlues";
}
override protected function playNow ( ):void
{
var playTune:PlayTune=new PlayTune(tuneName);
}
}
}

Free download pdf