static void Main(string[] args) { Duck mallard = new MallardDuck(); mallard.PerformQuack(); mallard.PerformFly(); // Quack // Flying mallard.QuackBehavior = new MuteQuack(); mallard.FlyBehavior = new FlyNoWay(); mallard.PerformQuack(); mallard.PerformFly(); // Silence // Can't Fly Console.ReadLine(); }
static void Main(string[] args) { Duck d = new MallardDuck(); d.quackingBehaviour = new Quack(); d.flyingBehaviour = new FlyWithWings(); d.PerformQuack(); Duck d2 = new ModelDuck(); d2.PerformFly(); d2.flyingBehaviour = new FlyWithRockets(); d2.PerformFly(); Console.ReadLine(); }
private static void Main(string[] args) { //The startegy pattern: defines a family of algorithms, encapsulates each one, and makes them interchangeable. //Strategy lets the algorithm vary independently from clients that use it. Duck mallard = new MallardDuck(); mallard.PerformQuack(); mallard.PerformFly(); Duck modelDuck = new ModelDuck(); modelDuck.PerformQuack(); modelDuck.PerformFly(); modelDuck.SetFlyBehavior(new FlyRocketPowered()); modelDuck.PerformFly(); Console.ReadLine(); }