static void Main(string[] args) { // Create Instances of Strategies and Contexts. Squeak theSqueak = new Squeak (); Quack theQuack = new Quack (); MuteQuack theMuteQuack = new MuteQuack (); FlyWithWings theFly = new FlyWithWings (); Flyless theFlyless = new Flyless (); Duck magicDuck = new MallardDuck(theQuack, theFly); Duck rorschachDuck = new RedheadDuck (theMuteQuack, theFlyless); // Call functions. magicDuck.display(); magicDuck.performQuack(); magicDuck.performFly(); Console.Out.WriteLine (); rorschachDuck.display(); rorschachDuck.performQuack(); rorschachDuck.performFly(); Console.Out.WriteLine (); // Assign new Strategies to Instances. magicDuck.QuackBehaviour = theSqueak; magicDuck.FlyBehaviour = theFlyless; rorschachDuck.QuackBehaviour = theQuack; rorschachDuck.FlyBehaviour = theFly; // Call functions. magicDuck.display(); magicDuck.performQuack(); magicDuck.performFly(); Console.Out.WriteLine (); rorschachDuck.display(); rorschachDuck.performQuack(); rorschachDuck.performFly(); Console.In.ReadLine(); }
static void Main(string[] args) { // Create Instances of Strategies and Contexts. Squeak theSqueak = new Squeak(); Quack theQuack = new Quack(); MuteQuack theMuteQuack = new MuteQuack(); FlyWithWings theFly = new FlyWithWings(); Flyless theFlyless = new Flyless(); Duck magicDuck = new MallardDuck(theQuack, theFly); Duck rorschachDuck = new RedheadDuck(theMuteQuack, theFlyless); // Call functions. magicDuck.display(); magicDuck.performQuack(); magicDuck.performFly(); Console.Out.WriteLine(); rorschachDuck.display(); rorschachDuck.performQuack(); rorschachDuck.performFly(); Console.Out.WriteLine(); // Assign new Strategies to Instances. magicDuck.QuackBehaviour = theSqueak; magicDuck.FlyBehaviour = theFlyless; rorschachDuck.QuackBehaviour = theQuack; rorschachDuck.FlyBehaviour = theFly; // Call functions. magicDuck.display(); magicDuck.performQuack(); magicDuck.performFly(); Console.Out.WriteLine(); rorschachDuck.display(); rorschachDuck.performQuack(); rorschachDuck.performFly(); Console.In.ReadLine(); }
public ModelDuck() { flyBehavior = new FlyNoWay(); quackBehavior = new Quack(); }
public MallardDuck() { Console.WriteLine("I'm mallard duck"); quackable = new Quack(); flyable = new FlyWithWing(); }
public MallardDuck() { quackBehavior = new Quack(); flyBehavior = new FlyWithWings(); }
public ModelDuck() { Console.WriteLine("I'm rubber duck"); flyable = new FlyNoWay(); quackable = new Quack(); }
public MullardDuck() { QuackBehavior = new Quack(); FlyBehavior = new FlyWithWings(); }