class Duck{
public var flyBehavior:FlyBehavior;
public var quackBehavior:QuackBehavior;
public function Duck(){
}
public function swim():Void{
}
public function display():Void{
}
public function performQuack():Void{
quackBehavior.quack();
}
public function performFly():Void{
flyBehavior.fly();
}
public function setFlyBehavior(fb:FlyBehavior):Void{
flyBehavior = fb;
}
public function setQuackBehavior(qb:QuackBehavior):Void{
quackBehavior = qb;
}
}
////////////////////////////////////////////////
interface FlyBehavior{
public function fly():Void;
}
////////////////////////////////////////////////
class FlyNoWay implements FlyBehavior{
public function fly():Void{
trace("저 안 날아요");
}
}
////////////////////////////////////////////////
class FlyWithWings implements FlyBehavior{
public function fly():Void{
trace("저 날아요");
}
}
////////////////////////////////////////////////
class ModelDuck extends Duck{
public function ModelDuck(){
flyBehavior = new FlyNoWay();
quackBehavior = new MuteQuack();
}
private function display():Void{
trace("가짜 오리입니다");
}
}
////////////////////////////////////////////////
class MuteQuack implements QuackBehavior{
public function quack():Void{
trace("나 벙어리");
}
}
///////////////////////////////////////////////
class Quack implements QuackBehavior{
public function quack():Void{
trace("꽥꽥");
}
}
/////////////////////////////////////////////////
interface QuackBehavior{
public function quack():Void;
}
/////////////////////////////////////////////////
class Squack implements QuackBehavior{
public function quack():Void{
trace("삑삑");
}
}
/////////////////////////////////////////////////
class Main{
private var myDuck:Duck;
public function Main(){
myDuck = new ModelDuck();
init();
}
private function init():Void{
myDuck.display();
myDuck.performFly();
myDuck.performQuack();
myDuck.setFlyBehavior(new FlyWithWings());
myDuck.performFly();
}
}
/////////////////////////////////////////////////