// 1. Strategy Pattern private static void RunStrategyPatternDemo() { // Normal Duck can not fly // Normal Duck can Quack Console.WriteLine("Initializing a Normal Duck"); Duck normalDuck = new NormalDuck(new FlyNoWay(), new Quack()); normalDuck.PerformFly(); normalDuck.PerformSound(); Console.WriteLine(); // Flying Duck can fly // Flying Duck can Quack Console.WriteLine("Initializing a Flying Duck"); Duck flyingDuck = new FlyingDuck(new FlyWithWings(), new Quack()); flyingDuck.PerformFly(); flyingDuck.PerformSound(); Console.WriteLine(); // Electronic Duck can not fly // Electronic Duck can Quack like Squeak // Electronic Duck can talk! Console.WriteLine("Initializing a Electronic Duck"); Duck electronicDuck = new ElectronicDuck(new FlyNoWay(), new Squeak(), new TalkBehavior()); electronicDuck.PerformFly(); electronicDuck.PerformSound(); Console.WriteLine(); }
static void Main(string[] args) { NormalDuck normalDuck = new NormalDuck(); SpecialDuck specialDuck = new SpecialDuck(); normalDuck.performFly(); normalDuck.performQuack(); specialDuck.performFly(); specialDuck.performQuack(); }
static void Main(string[] args) { Duck robotDuck = new RobotDuck(); robotDuck.Fly(); robotDuck.Quack(); Duck normalDuck = new NormalDuck(); normalDuck.Fly(); normalDuck.Quack(); Duck modelDuck = new ModelDuck(new NoFlyStrategy(), new HighPitchQuackStrategy()); modelDuck.Fly(); modelDuck.Quack(); Console.ReadLine(); }