Esempio n. 1
0
        static void Main(string[] args)
        {
            DuckBase duck1 = new MallardDuck("Mallard Duck");

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

            DuckBase duck2 = new DecoyDuck("Decoy Duck");

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

            DuckBase duck3 = new RubberDuck("Rubber Duck");

            duck3.Display();
            duck3.Swim();
            duck3.PerformFly();
            duck3.PerformQuack();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Duck num1 = new MallardDuck();

            num1.display();
            num1.performFly();
            num1.performQuack();
            num1.Swim();

            Duck num2 = new RedheadDuck();

            num2.display();
            num2.performFly();
            num2.performQuack();
            num2.Swim();

            Duck num3 = new DecoyDuck();

            num3.display();
            num3.performFly();
            num3.performQuack();
            num3.Swim();
            num3.setFlyBehavior(new FlyWithWings());
            num3.performFly();

            Console.Read();
        }
Esempio n. 3
0
        static void Main(string[] args) {

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

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

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

            Console.ReadKey();
        }