Example #1
0
        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();
        }
Example #2
0
        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();
        }
Example #3
0
 public ModelDuck()
 {
     flyBehavior   = new FlyNoWay();
     quackBehavior = new Quack();
 }
Example #4
0
 public MallardDuck()
 {
     Console.WriteLine("I'm mallard duck");
     quackable = new Quack();
     flyable   = new FlyWithWing();
 }
Example #5
0
 public MallardDuck()
 {
     quackBehavior = new Quack();
     flyBehavior   = new FlyWithWings();
 }
Example #6
0
 public ModelDuck()
 {
     Console.WriteLine("I'm rubber duck");
     flyable   = new FlyNoWay();
     quackable = new Quack();
 }
Example #7
0
 public MullardDuck()
 {
     QuackBehavior = new Quack();
     FlyBehavior   = new FlyWithWings();
 }