change the flight in strategy

This commit is contained in:
Alexander Zhirov 2022-11-10 00:29:18 +03:00
parent 8284e0f476
commit e9712fdf28
2 changed files with 13 additions and 0 deletions

View File

@ -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();
} }

View File

@ -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