Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(" ** This is Duck Fly Learning Program from Head First Design Patterns \n Chap 1 - Strategy Pattern ** \n\n");

            Duck mallard = new MallardDuck();

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

            Console.WriteLine();

            Duck redhead = new RedheadDuck();

            redhead.display();
            redhead.performQuack();
            redhead.performFly();

            Console.WriteLine();

            Duck rubber = new RubberDuck();

            rubber.display();
            rubber.performQuack();
            rubber.performFly();

            Console.WriteLine();
            Console.WriteLine("Adding Rocket Power to Rubber Duck");
            Console.WriteLine();

            // setting fly behavior for rubber ducky
            rubber.setFlyBehavior = new FlyRocketPowered();
            rubber.display();
            rubber.performFly();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //***** DUCKS
            Duck mallard = new MallardDuck();

            mallard.performQuack();
            mallard.performFly();
            mallard.display();
            mallard.setQuackBehaviour(new Squek());
            mallard.performQuack();

            Duck model = new ModelDuck();

            model.performQuack();
            model.display();
            model.setFlyBehavior(new FlyRocketPowered());
            model.performFly();

            Console.ReadKey();

            //***** CHOCOLATE FACTORY

            /*
             * ChocolateBoiler CB = ChocolateBoiler.getInstance();
             * CB.fill();
             * CB.boil();
             *
             * Console.WriteLine("Hello World! Is the chocolate factory boiled? "+ CB.isBoiled());
             * Console.ReadKey();
             */
        }
Beispiel #3
0
    public static void Main(String[] args)
    {
        MallardDuck mallard = new MallardDuck();

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

            mallardDuck.display();
            mallardDuck.performQuack();
            mallardDuck.performFly();

            var RubberDuck = new RubberDucky();

            RubberDuck.performFly();
            RubberDuck.display();
            RubberDuck.performQuack();

            WriteLine("______________________");
            Duck model = new ModelDuck();

            model.performFly();
            model.flyBehavior = new FlyRocketPowered();
            model.performFly();
        }
Beispiel #5
0
        public static void RevisaoPOO1()
        {
            Duck        duck        = new Duck();
            MallardDuck mallardDuck = new MallardDuck();
            RubberDuck  rubberDuck  = new RubberDuck();
            RedHeadDuck redHeadDuck = new RedHeadDuck();

            duck.display();
            duck.swim();

            mallardDuck.display();
            mallardDuck.quack();
            mallardDuck.fly();

            rubberDuck.display();
            rubberDuck.quack();

            redHeadDuck.display();
            redHeadDuck.fly();
            redHeadDuck.quack();
        }
        static void Main(string[] args)
        {
            OptionsEnum option;;

            while ((option = getOption()) == OptionsEnum.Unknown)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error en la opción ingresada");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine();
            }

            switch (option)
            {
            case OptionsEnum.StrategyPattern:
            {
                MallardDuck mallardDuck = new MallardDuck();
                Console.WriteLine(mallardDuck.display());
                Console.WriteLine(mallardDuck.performQuack());
                Console.WriteLine(mallardDuck.performFly());

                // Change behavior dynamically
                Console.WriteLine("Changing dynamically behaviour of mallard duck...");
                mallardDuck.setFlyBehavior(new FlyNoWay());
                mallardDuck.setQuackBehavior(new Squeak());
                Console.WriteLine(mallardDuck.display());
                Console.WriteLine(mallardDuck.performQuack());
                Console.WriteLine(mallardDuck.performFly());
            }
            break;

            case OptionsEnum.ObserverPattern:
            {
                //WeatherData weatherData = new WeatherData();
                //CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);
                //ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData, 29.92f);
                ObserverPattern.SecondSolution.WeatherData weatherData = new ObserverPattern.SecondSolution.WeatherData();
                ObserverPattern.SecondSolution.CurrentConditionsDisplay currentConditionsDisplay = new ObserverPattern.SecondSolution.CurrentConditionsDisplay(weatherData);
                ObserverPattern.SecondSolution.ForecastDisplay          forecastDisplay          = new ObserverPattern.SecondSolution.ForecastDisplay(weatherData, 29.92f);
                Console.WriteLine("Setting measurements (t, h, p) = (80, 65, 30.4)...");
                weatherData.setMeasurements(80, 65, 30.4f);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(currentConditionsDisplay.display());
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(forecastDisplay.display());
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Setting measurements (t, h, p) = (82, 70, 29.2)...");
                weatherData.setMeasurements(82, 70, 29.2f);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(currentConditionsDisplay.display());
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(forecastDisplay.display());
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Setting measurements (t, h, p) = (78, 90, 29.2)...");
                weatherData.setMeasurements(78, 90, 29.2f);
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(currentConditionsDisplay.display());
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(forecastDisplay.display());
                Console.ForegroundColor = ConsoleColor.White;
            }
            break;
            }


            Console.ReadKey();
        }