static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();
            mallard.Display();
            mallard.PerformQuack();
            mallard.PerformFly();

            Duck fauxDuck = new ModelDuck();
            fauxDuck.Display();
            fauxDuck.PerformQuack();
            fauxDuck.PerformFly();

            Duck disabledMallard = new MallardDuck()
                {
                    FlyBehavior = new CannotFlyBehavior(),
                    QuackBehavior = new MuteBehavior()
                };
            disabledMallard.Display();
            disabledMallard.PerformFly();
            disabledMallard.PerformQuack();

            fauxDuck.FlyBehavior = new JetPackBehavior();
            fauxDuck.Display();
            fauxDuck.PerformFly();

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.PerformQuack();
            mallard.PerformFly();

            Console.ReadLine();
        }
        static void Main(string[] args) {

            Duck mallard = new MallardDuck();
            mallard.PerformFly();
            mallard.PerformQuak();
            mallard.Display();
            mallard.Swim();

            Console.ReadKey();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var mallard = new MallardDuck {
                Quacker = new QuackNormal()
            };

            mallard.Display();
            mallard.Flyer = new FlyWings();
            mallard.Display();
        }
        private void CreateMallardDuckWithRocketAndSqueak()
        {
            Duck mallardDuck = new MallardDuck();

            mallardDuck.SetFlyBehavior(new FlyRocketPowered());
            mallardDuck.SetQuackBehavior(new Squeak());
            mallardDuck.Display();
            mallardDuck.PerformFly();
            mallardDuck.PerformQuack();
        }
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.PerformFly();
            mallard.PerformQuak();
            mallard.Display();
            mallard.Swim();

            Console.ReadKey();
        }
Beispiel #7
0
        //Design principle
        //Identify the aspects of your
        //application that vary and separate
        //them from what stays the same.

        //Design principle
        //Program to an interface (abstract class/interface), not an
        //implementation.

        //Design principle
        //Favor composition over inheritance

        //The Strategy Pattern defines a family of algorithms,
        //encapsulates each one, and makes them interchangeable.
        //Strategy lets the algorithm vary independently from
        //clients that use it.
        static void Main(string[] args)
        {
            MallardDuck mallardDuck = new MallardDuck();

            mallardDuck.PerformFly();
            mallardDuck.SetFlyBehavior(new FlyRocketPowered());
            mallardDuck.PerformFly();
            mallardDuck.PerformQuack();
            mallardDuck.Display();
            mallardDuck.Swim();
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            Duck mallardDuck = new MallardDuck();

            mallardDuck.PerformFly();
            mallardDuck.PerformQuack();

            Duck plasticDuck = new PlasticDuck();

            plasticDuck.PerformFly();
            plasticDuck.PerformQuack();
        }
Beispiel #9
0
        static void Main()
        {
            Duck mallard = new MallardDuck();

            mallard.PerformQuack();
            mallard.PerformFly();

            Duck model = new ModelDuck();

            model.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.performQuack();
            mallard.performFly();

            Duck model = new ModelDuck();

            model.performFly();
            model.flyBehavior = new FlyRocketPowered();
            model.performFly();
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("These three ducks may give you a good day!\n");
            Duck duck1 = new MallardDuck();
            Duck duck2 = new RubberDuck();
            Duck duck3 = new DecoyDuck();

            DisplayProperties(duck1);
            DisplayProperties(duck2);
            DisplayProperties(duck3);

            Console.ReadLine();
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            var mallard = new MallardDuck();

            mallard.PerformFly();
            mallard.PerformQuack();

            var modelDuck = new ModelDuck();

            modelDuck.PerformQuack();
            modelDuck.PerformFly();
            modelDuck.SetFlyBehavior(new FlyRocketPowered());
            modelDuck.PerformFly();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.performQuack();
            mallard.performFly();

            //model duck dynamically changed its flying behavior
            Duck model = new ModelDuck();

            model.performFly();
            model.setFlyBehavior(new FlyRocketPowered());
            model.performFly();
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck(new Quack(), new FlyWithWings());

            mallard.performQuack();
            mallard.performFly();

            Duck model = new ModelDuck(new Quack(), new FlyNoWay());

            model.performFly();
            model.flyBehavior = new FlyRockectPowered();
            model.performFly();
            model.performQuack();
            Console.Read();
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.performQuack();
            mallard.performFly();

            Duck model = new ModelDuck();

            model.performFly();
            model.setFlyBehavior(new FlyRocketPowerd());
            model.performFly();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Duck mallardDuck = new MallardDuck();

            mallardDuck.Display();
            mallardDuck.flyBehavior.DoFly();
            mallardDuck.quackBehavior.DoQuack();

            Console.WriteLine();

            Duck rubberDuck = new RubberDuck();

            rubberDuck.Display();
            rubberDuck.flyBehavior.DoFly();
            rubberDuck.quackBehavior.DoQuack();
        }
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.Display();
            mallard.PerformFly();
            mallard.PerformQuack();

            Console.WriteLine();

            Duck model = new ModelDuck();

            model.Display();
            model.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();
        }
Beispiel #18
0
        private static void MiniDuckSimulator()
        {
            var mallard = new MallardDuck();

            mallard.Display();
            mallard.PerformFly();
            mallard.PerformQuack();

            var model = new ModelDuck();

            model.Display();
            model.PerformFly();
            model.PerformQuack();
            Console.WriteLine("---------\r\n>>> powered by rocket.");
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();
        }
Beispiel #19
0
        static void Main()
        {
            Duck mallard = new MallardDuck();

            mallard.performFly();
            mallard.performQuack();
            mallard.display();


            Duck model = new ModelDuck();

            model.performFly();
            model.setFlyBehaviour(new FlyRocketPowered());
            model.performFly();

            Console.ReadKey();
        }
        /** The Strategy Pattern defines a family of algorithms,
         *      encapsulates each one, and makes them interchangeable.
         *      Strategy lets the algortihm vary independently from
         *      clients that use it.
         *
         *      In this case it allows to quickly add new properties
         *      like allow different ducks to swim, each of them could
         *      swim differently and so on */
        static void Main(string[] args)
        {
            var mallard = new MallardDuck();

            mallard.Display();
            mallard.PerformFly();
            mallard.PerformQuack();
            Console.WriteLine();

            var displayDuck = new DisplayDuck();

            displayDuck.Display();
            displayDuck.PerformFly();
            displayDuck.PerformQuack();
            Console.WriteLine();
            displayDuck.SetFly(new FlyWithWings());
            displayDuck.PerformFly();
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            Duck Mallard = new MallardDuck();

            Mallard.performFly();
            Mallard.performQuack();

            Duck model = new ModelDuck();

            model.performFly();
            model.setFlyBehaviour(new FlyWithWings());
            model.performFly();

            //no vuela
            Duck model2 = new ModelDuck();

            model.performFly();
            model.setFlyBehaviour(new FlyNoWay());
            model.performFly();
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            Duck myDuck = new MallardDuck();

            myDuck.Display();
            myDuck.PerformFly();
            myDuck.PerformQuack();
            myDuck.SetFlyBehavior(new FlyWithWingsTypeTwo());
            myDuck.SetQuackBehavior(new NoQuack());
            myDuck.PerformFly();
            myDuck.PerformQuack();

            myDuck = new RubberDuck();
            myDuck.Display();
            myDuck.PerformFly();
            myDuck.PerformQuack();
            myDuck.SetFlyBehavior(new FlyWithJet());
            myDuck.SetQuackBehavior(new QuackLikeMallardDuck());
            myDuck.PerformFly();
            myDuck.PerformQuack();
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            Duck Mallard = new MallardDuck();

            Mallard.Display();
            Mallard.PerformQuack();
            Mallard.PerformFly();

            Duck Model = new ModelDuck();

            Console.WriteLine();
            Model.Display();
            Model.PerformQuack();
            Model.PerformFly();
            Model.SetFlyBehavior(new FlyRocketPowered());
            Model.PerformFly();

            Duck Redhead = new RedheadDuck();

            Console.WriteLine();
            Redhead.Display();
            Redhead.PerformQuack();
            Redhead.PerformFly();

            Duck Rubber = new RubberDuck();

            Console.WriteLine();
            Rubber.Display();
            Rubber.PerformQuack();
            Rubber.PerformFly();

            Duck Decoy = new DecoyDuck();

            Console.WriteLine();
            Decoy.Display();
            Decoy.PerformQuack();
            Decoy.PerformFly();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Duck App");
            Console.WriteLine("-------------------");
            Console.WriteLine("Mallard Duck.");
            Duck mallard = new MallardDuck();

            //this call the mallardDuck's inherited fly and quack method which the delegates the object's Behvior.
            mallard.Fly();
            mallard.Quack();
            Console.WriteLine("-------------------");


            Console.WriteLine("Mallard Duck with setting dynamic behaviour");
            //setting the behavior dynamically
            Duck dynamicMallard = new MallardDuck();

            dynamicMallard.SetFly(new FlyWithWings());
            dynamicMallard.Fly();
            dynamicMallard.SetQuack(new Quack());
            dynamicMallard.Quack();
            Console.ReadKey();
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            Console.WriteLine("We have four ducks available for the showcase.");
            Console.WriteLine("Choose one of these and type the number. ex) 1 = DecoyDuck");
            Console.WriteLine("");
            Console.WriteLine("1. DecoyDuck");
            Console.WriteLine("2. MallardDuck");
            Console.WriteLine("3. RedheadDuck");
            Console.WriteLine("4. RubberDuck");
            Console.WriteLine("");

            string end = String.Empty;

            do
            {
                Duck duck = default(Duck);

                string s = Console.ReadLine();
                if (!String.IsNullOrEmpty(s) && int.TryParse(s, out int result))
                {
                    switch (result)
                    {
                    case 1:
                    {
                        duck = new DecoyDuck();
                        duck.setFlyBehavior(new FlyNoWay());
                        duck.setQuackHeavior(new MuteQuack());
                    }
                    break;

                    case 2:
                    {
                        duck = new MallardDuck();
                        duck.setFlyBehavior(new FlyWithWings());
                        duck.setQuackHeavior(new StrategyPattern.Quack.Quack());
                    }
                    break;

                    case 3:
                    {
                        duck = new RedheadDuck();
                        duck.setFlyBehavior(new FlyWithWings());
                        duck.setQuackHeavior(new Squeak());
                    }
                    break;

                    case 4:
                    {
                        duck = new RubberDuck();
                        duck.setFlyBehavior(new FlyNoWay());
                        duck.setQuackHeavior(new MuteQuack());
                    }
                    break;

                    default:
                    {
                        Console.WriteLine("You choose a duck that is not on the list. I'm gonna just show you a rubber duck !");

                        duck = new RubberDuck();
                        duck.setFlyBehavior(new FlyNoWay());
                        duck.setQuackHeavior(new MuteQuack());
                    }
                    break;
                    }
                }
                else
                {
                    Console.WriteLine("Input only numbers. Don't type their names.");
                }

                duck.display();
                duck.performFly();
                duck.performQuack();
                duck.swim();

                end = Console.ReadLine();
            } while (end != "exit");
        }
        private void CreateMallardDuck()
        {
            Duck mallardDuck = new MallardDuck();

            mallardDuck.Execute();
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            Console.WriteLine(mallard.performFly());
        }