Esempio n. 1
0
        static void Main(string[] args)
        {
            IWalkBehavior walkBehavior = new WalkBehaviorD();
            IDuck         duck         = new WildDuck(walkBehavior);
            IDuck         cityDuck     = new CityDuck();
            IDuck         mountainDuck = new MountainDuck();
            IDuck         cloudDuck    = new CloudDuck();

            Console.WriteLine(duck.Fly());
            Console.WriteLine(cityDuck.Fly());
            Console.WriteLine(mountainDuck.Fly());
            Console.WriteLine(mountainDuck.Fly());
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Duck cityduck = new CityDuck();

            cityduck.PerformFly();
            cityduck.PerformQuack();


            Duck rubberduck = new RubberDuck();

            rubberduck.PerformFly();
            rubberduck.PerformQuack();
            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();
        }