static void Main(string[] args)
        {
            // Pato Bravo
            MallardDuck md = new MallardDuck();
            md.Display();
            md.Swim();
            md.Fly();
            md.Quack();
            System.Console.WriteLine("\n");

            // Pato Cabeça-vermelha
            RedHeadDuck rhd = new RedHeadDuck();
            rhd.Display();
            rhd.Swim();
            rhd.Fly();
            rhd.Quack();
            System.Console.WriteLine("\n");

            // Pato de Borracha
            RubberDuck rd = new RubberDuck();
            rhd.Display();
            rhd.Swim();
            rd.Quack(); // Chia invés de grasnar
            System.Console.WriteLine("\n");

            // Pato de Madeira
            DecoyDuck dd = new DecoyDuck();
            dd.Display();
            dd.Swim();
            System.Console.WriteLine("\n");

            System.Console.ReadKey();
        }
Beispiel #2
0
        private static void Main()
        {
            var mallardDuck = new MallardDuck();

            mallardDuck.Display();
            mallardDuck.PerformQuack();
            mallardDuck.Swim();
            mallardDuck.PerformFly();
            Console.WriteLine();

            var redheadDuck = new RedheadDuck();

            redheadDuck.Display();
            redheadDuck.PerformQuack();
            redheadDuck.Swim();
            redheadDuck.PerformFly();
            Console.WriteLine();

            var rubberDuck = new RubberDuck();

            rubberDuck.Display();
            rubberDuck.PerformQuack();
            rubberDuck.Swim();
            rubberDuck.PerformFly();
            Console.WriteLine();

            var decoyDuck = new DecoyDuck();

            decoyDuck.Display();
            decoyDuck.Swim();
            Console.WriteLine();

            Console.Write("Press Enter to exit ...");
            Console.ReadLine();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var ducks = new List <Duck>()
            {
                new Mallard(new FlyWithWingsBehavior(), new QuackBehavior()),
                new WoodDuck(new FlyWithWingsBehavior(), new QuackBehavior()),
                // Making changes in the same spot as another user, and I haven't pulled their changes.
                new WoodDuck(new FlyWithWingsBehavior(), new NoSoundBehavior()),
                new WoodDuck(new NoFlyBehavior(), new QuackBehavior()),
                new RubberDuck(new NoFlyBehavior(), new QuackBehavior()),
                // end of changes.
                // This will simulate changes made by another user.
                new Mallard(new NoFlyBehavior(), new NoSoundBehavior()),
                new RubberDuck(new FlyWithWingsBehavior(), new QuackBehavior()), //yes, a quacking, flying rubber duck
                new DecoyDuck(new NoFlyBehavior(), new QuackBehavior()),
                // End of new ducks
                new RubberDuck(new NoFlyBehavior(), new NoSoundBehavior()),
                new DecoyDuck(new NoFlyBehavior(), new NoSoundBehavior())
            };

            foreach (var duck in ducks)
            {
                Console.WriteLine(duck.ToString());
                duck.Display();
                duck.MakeSound();
                duck.PerformFly();
                if (duck is ICanSwim swimmingDuck)
                {
                    swimmingDuck.Swim();
                }

                Console.WriteLine();
            }

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Decoy Duck sample");
            var decoyDuck = new DecoyDuck(new NoFlyBehavior(), new NoSoundBehavior());

            decoyDuck.Swim();
            decoyDuck.SetSwimBehavior(new SubmarineSwimBehavior());
            decoyDuck.Swim();

            ShowFlyableThings();

            Console.ReadKey();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // Pato Bravo
            MallardDuck md = new MallardDuck();

            md.Display();
            md.Swim();
            md.Fly();
            md.Quack();
            System.Console.WriteLine("\n");

            // Pato Cabeça-vermelha
            RedHeadDuck rhd = new RedHeadDuck();

            rhd.Display();
            rhd.Swim();
            rhd.Fly();
            rhd.Quack();
            System.Console.WriteLine("\n");

            // Pato de Borracha
            RubberDuck rd = new RubberDuck();

            rhd.Display();
            rhd.Swim();
            rd.Quack(); // Chia invés de grasnar
            System.Console.WriteLine("\n");

            // Pato de Madeira
            DecoyDuck dd = new DecoyDuck();

            dd.Display();
            dd.Swim();
            System.Console.WriteLine("\n");


            System.Console.ReadKey();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var mallardDuck = new MallardDuck();

            mallardDuck.QuackBehavior = new QuackAsNormal();
            mallardDuck.FlyBehavior   = new FlyWithWings();
            Console.WriteLine($"Mallard duck {new string('-', 50)}");
            mallardDuck.Swim();
            mallardDuck.PerformQuack();
            mallardDuck.PerformFly();

            var redheadDuck = new RedheadDuck();

            redheadDuck.QuackBehavior = new QuackAsNormal();
            redheadDuck.FlyBehavior   = new FlyWithWings();
            Console.WriteLine($"Redhead duck {new string('-', 50)}");
            redheadDuck.Swim();
            redheadDuck.PerformQuack();
            redheadDuck.PerformFly();

            var rubberDuck = new RubberDuck();

            rubberDuck.QuackBehavior = new Sqeak();
            rubberDuck.FlyBehavior   = new FlyNoWay();
            Console.WriteLine($"Rubber duck {new string('-', 50)}");
            rubberDuck.Swim();
            rubberDuck.PerformQuack();
            rubberDuck.PerformFly();

            var decoyDuck = new DecoyDuck();

            decoyDuck.QuackBehavior = new Mute();
            decoyDuck.FlyBehavior   = new FlyNoWay();
            Console.WriteLine($"Decoy duck {new string('-', 50)}");
            decoyDuck.Swim();
            decoyDuck.PerformQuack();
            decoyDuck.PerformFly();
        }