【AS3代码】抽象类简单运用
抽象类
package
{
import flash.display.Sprite;
public class initialize extends Sprite
{
public function initializes():void
{
createField();
createTeam("red");
createTeam("blue");
startGame();
}
public function createField():void
{
//throw new Error("抽象方法!");
}
public function createTeam(name:String):void
{
//throw new Error("抽象方法!");
}
public function startGame():void
{
//throw new Error("抽象方法!");
}
}
}
{
import flash.display.Sprite;
public class initialize extends Sprite
{
public function initializes():void
{
createField();
createTeam("red");
createTeam("blue");
startGame();
}
public function createField():void
{
//throw new Error("抽象方法!");
}
public function createTeam(name:String):void
{
//throw new Error("抽象方法!");
}
public function startGame():void
{
//throw new Error("抽象方法!");
}
}
}
继承抽象类:
package
{
public class FootballGame extends initialize
{
public function FootballGame()
{
}
public override function createField():void
{
trace("创建足球!");
}
public override function createTeam(name:String):void
{
trace("创建足球队,名字:" + name);
}
public override function startGame():void
{
trace("开始足球游戏");
}
}
}
{
public class FootballGame extends initialize
{
public function FootballGame()
{
}
public override function createField():void
{
trace("创建足球!");
}
public override function createTeam(name:String):void
{
trace("创建足球队,名字:" + name);
}
public override function startGame():void
{
trace("开始足球游戏");
}
}
}
文档类:
package
{
import flash.display.Sprite;
public class FactoryExample extends Sprite
{
public function FactoryExample()
{
var game:FootballGame = new FootballGame();
game.initializes();
}
}
}
{
import flash.display.Sprite;
public class FactoryExample extends Sprite
{
public function FactoryExample()
{
var game:FootballGame = new FootballGame();
game.initializes();
}
}
}