static void Main(string[] args)
        {
            /*
             * Design principle: Identify the aspects of your application that vary and separate them from what stays the same.
             *
             * Design principle: Program to an 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.
             */

            Duck mallard = new MallardDuck();

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


            Duck model = new ModelDuck();

            model.display();
            model.PerformQuack();
            model.PerformFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.PerformFly();

            Console.ReadKey();
        }
Exemple #2
0
        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();
        }
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

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

            Duck model = new ModelDuck();

            model.Display();
            model.PerformQuack();
            model.PerformFly();
            model.SetFlyBehaviour(new FlyRocketPowered());
            model.PerformFly();
            Console.WriteLine();

            Duck decoy = new DecoyDuck();

            decoy.Display();
            decoy.PerformQuack();
            decoy.PerformFly();
            decoy.SetQuackBehaviour(new Squeak());
            Console.WriteLine();

            Duck rubber = new RubberDuck();

            rubber.Display();
            rubber.PerformQuack();
            rubber.PerformFly();
            rubber.Swim();
            Console.WriteLine();
        }
        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();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            List <Duck> pond = new List <Duck>();//пруд с уточками

            pond.Add(new MallardDuck());
            pond.Add(new ModelDuck());

            foreach (Duck duck in pond)
            {
                duck.display();
                duck.performQuack();
                duck.performFly();
                Console.WriteLine("");
            }
            Console.WriteLine("Load force");
            Console.WriteLine("Ready to start!");
            Console.WriteLine("");
            Duck forced = new ModelDuck();

            forced.setFlyBehavior(new ReactiveFlying());

            forced.display();
            forced.performQuack();
            forced.performFly();

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            var model = new ModelDuck();

            model.PerformFly();
            model.SetFlyBehavior(new FlySoFast());
            model.PerformFly();
            Console.ReadLine();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            //Duck.Duck mallard = new MallardDuck();
            //mallard.PerformQuack();
            //mallard.PerformFly();

            Duck.Duck model = new ModelDuck();
            model.PerformFly();
            model.setFlyBehavior(new FlyRocketPowered());
            model.PerformFly();
        }
Exemple #8
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();
        }
Exemple #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();
        }
        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();
        }
Exemple #11
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();
        }
Exemple #12
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();
        }
Exemple #13
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();
        }
        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();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            Duck greenDuck = new GreenDuck();
            greenDuck.PeformaneFly();
            greenDuck.PeformaneQuack();

            Duck modelDuck = new ModelDuck();
            modelDuck.PeformaneFly();
            modelDuck.PeformaneQuack();

            modelDuck.setFlyBehavior(new FlyWithWing());
            modelDuck.setQuackBehavior(new MuteSqueak());
            modelDuck.PeformaneFly();
            modelDuck.PeformaneQuack();

            Console.ReadLine();
        }
Exemple #16
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();
        }
Exemple #17
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();
        }
Exemple #18
0
        static void Main(string[] args)
        {
            Duck robotDuck = new RobotDuck();

            robotDuck.Fly();
            robotDuck.Quack();

            Duck normalDuck = new NormalDuck();

            normalDuck.Fly();
            normalDuck.Quack();

            Duck modelDuck = new ModelDuck(new NoFlyStrategy(), new HighPitchQuackStrategy());

            modelDuck.Fly();
            modelDuck.Quack();

            Console.ReadLine();
        }
Exemple #19
0
        static void Main(string[] args)
        {
            Duck greenDuck = new GreenDuck();

            greenDuck.PeformaneFly();
            greenDuck.PeformaneQuack();

            Duck modelDuck = new ModelDuck();

            modelDuck.PeformaneFly();
            modelDuck.PeformaneQuack();

            modelDuck.setFlyBehavior(new FlyWithWing());
            modelDuck.setQuackBehavior(new MuteSqueak());
            modelDuck.PeformaneFly();
            modelDuck.PeformaneQuack();

            Console.ReadLine();
        }
Exemple #20
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();
        }
        static void Main(string[] args)
        {
            Duck real = new RealDuck();

            real.Display();
            real.PerformFly();
            real.PerformQuack();

            real.SetFlyBehavior(new FlyNoWay());
            real.PerformFly();

            Duck model = new ModelDuck();

            model.Display();
            model.PerformFly();
            model.PerformQuack();

            model.SetQuackBehavior(new DuckQuack());
            model.PerformQuack();

            Console.Read();
        }
Exemple #22
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();
        }
        private void CreateModelDuck()
        {
            Duck modelDuck = new ModelDuck();

            modelDuck.Execute();
        }