Esempio n. 1
0
        static void Main(string[] args)
        {
            Duck jungleDuck = new WildDuck(new DisplayingGraphically(), new HighFlying(), new LoudQuacking());

            jungleDuck.Fly();
            jungleDuck.Display();
            jungleDuck.Quack();

            Duck cityDuck = new RubberDuck(new DisplayingText(), new GroundFlying(), new NoQuacking());

            cityDuck.Fly();
            cityDuck.Display();
            cityDuck.Quack();
            Console.ReadLine();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            WildDuck wildDuck = new WildDuck();

            wildDuck.Quack();
            wildDuck.Fly();

            RubberDuck rubberDuck = new RubberDuck();

            rubberDuck.Quack();
            rubberDuck.Fly();
            rubberDuck.Flying = new Flying();
            rubberDuck.Fly();


            Console.ReadLine();
        }
        /// <summary>
        /// Definition:
        /// The strategy pattern defines a family of algorithms, encapsulates each one and makes them interchangeable.
        /// Strategy lets the algorithm very independently from clients that use it.
        /// </summary>
        static void Main(string[] args)
        {
            WildDuck wildDuck = new WildDuck();
            CityDuck cityDuck = new CityDuck();

            Console.WriteLine("\n--- The wild duck ---");
            wildDuck.Quack();
            wildDuck.Fly();
            wildDuck.Display();

            Console.WriteLine("\n--- The city duck ---");
            cityDuck.Quack();
            cityDuck.Fly();
            cityDuck.Display();


            Console.ReadKey();
        }