change the flight in strategy
This commit is contained in:
parent
8284e0f476
commit
e9712fdf28
|
@ -1,6 +1,7 @@
|
||||||
module strategy.app;
|
module strategy.app;
|
||||||
|
|
||||||
import strategy.duck;
|
import strategy.duck;
|
||||||
|
import strategy.flybehavior;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@ -11,4 +12,6 @@ void main()
|
||||||
Duck model = new ModelDuck;
|
Duck model = new ModelDuck;
|
||||||
model.performQuack();
|
model.performQuack();
|
||||||
model.performFly();
|
model.performFly();
|
||||||
|
model.setFlyBehavior(new FlyRocketPowered);
|
||||||
|
model.performFly();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,16 @@ abstract class Duck
|
||||||
{
|
{
|
||||||
writeln("All ducks float, even decoys!");
|
writeln("All ducks float, even decoys!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setFlyBehavior(FlyBehavior fb)
|
||||||
|
{
|
||||||
|
flyBehavior = fb;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setQuackBehavior(QuackBehavior qb)
|
||||||
|
{
|
||||||
|
quackBehavior = qb;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MallardDuck : Duck
|
class MallardDuck : Duck
|
||||||
|
|
Reference in New Issue