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