module strategy.duck; import strategy.flybehavior; import strategy.quackbehavior; import std.stdio : writeln; abstract class Duck { FlyBehavior flyBehavior; QuackBehavior quackBehavior; void display(); void performFly() { flyBehavior.fly(); } void performQuack() { quackBehavior.quack(); } void swim() { writeln("All ducks float, even decoys!"); } } class MallardDuck : Duck { this() { quackBehavior = new Quack; flyBehavior = new FlyWithWings; } override void display() { writeln("I'm a real Mallard duck"); } } class ModelDuck : Duck { this() { quackBehavior = new Squeak; flyBehavior = new FlyNoWay; } override void display() { writeln("I'm a model duck"); } }