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

The Referee

Because the Referee class is abstract, it's relatively small. The methods are fairly general with the idea that they can be overridden; however, they must be purposely developed. Further, because they'll be placed in a template method, they have to be developed with an eye to the order in which they'll be placed. We'll begin with a look at the Referee class to get an overview and then look at the methods for the class. Example 13-2 shows the Referee class.

Example 13-2. Referee.as

package
{
    //Abstract Class
    public class Referee
    {
        //Move
        private var p1Move:String;//Player 1's move
        private var p2Move:String;//Player 2's move
        private var winner:String;//Value for winner
        private var outcome:String;//Describe winnder
        private var displayWindow:DynamicText;
        private var movecheck:Array;//Array to keep track of moves

        //Template Method
        final function moveComplete(p1Move:String,p2Move:String,
             displayWindow:DynamicText,movecheck:Array):void
        {
            outcome=doWinner(p1Move,p2Move);
            displayResults(displayWindow,outcome);
            resetGame(movecheck);
        }

        //Abstract methods

        protected function doWinner(p1Move:String,p2Move:String):String
        {
            return winner;
        }
        function displayResults(displayWindow:DynamicText,
             outcome:String):void
        {
            displayWindow.setMove(outcome);
        }
        protected function resetGame(movecheck:Array):void
        {
            for (var r:uint =0; r< movecheck.length; r++)
            {
                movecheck[r]=false;
            }
        }
    }
}

The comment at the top of the class indicating that the class is an abstract one is simply a comment. It stands as ...

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