示例#1
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();
             */
        }
示例#2
0
        public static void Run(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.performQuack();
            mallard.performFly();
        }
示例#3
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();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start!");
            Duck mallard = new MallardDuck();

            mallard.performQuack();
            Console.WriteLine("Done!");

            Console.WriteLine("Press enter to quit...");
            Console.ReadLine();
        }
    public static void Test()
    {
        Duck mallard = new MallardDuck();

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

        Duck model = new ModelDuck();

        model.performFly();
        model.setFlyBehavior(new FlyRocketPowered());
        model.performFly();
    }
示例#6
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

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

            Duck model = new ModelDuck();

            model.performFly();
            // Dynamically update a class at runtime
            model.FlyBehavior = new FlyRocketPowered();
            model.performFly();

            DuckCall duckCall = new DuckCall();

            duckCall.performQuack();
        }
示例#7
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();
        }
示例#8
0
文件: Program.cs 项目: phcbarros/.Net
        static void Main(string[] args)
        {
            Model.Duck duck = new DecoyDuck();

            //pato de decoração
            Console.WriteLine("Comportamentos de um pato de decoração");
            Console.WriteLine("Vôo: {0}", duck.perfomFly());
            Console.WriteLine("Grasnar: {0}", duck.performQuack());
            Console.WriteLine();

            //pato Mallard
            duck = new MallardDuck();
            Console.WriteLine("Comportamentos de um pato Mallard");
            Console.WriteLine("Vôo: {0}", duck.perfomFly());
            Console.WriteLine("Grasnar: {0}", duck.performQuack());
            Console.WriteLine();

            //pato modelo
            duck = new ModelDuck();
            Console.WriteLine("Comportamentos de um pato modelo");
            Console.WriteLine("Vôo: {0}", duck.perfomFly());
            Console.WriteLine("Grasnar: {0}", duck.performQuack());
            Console.WriteLine();

            Console.WriteLine("Mudando o comportamento do pato modelo em tempo de execução");
            Console.WriteLine();

            duck.alterarQuackBehavior(new Squeak());
            duck.alterarFlyBehavior(new FlyRocketPowered());
            Console.WriteLine("Comportamentos de um pato modelo alterado");
            Console.WriteLine("Vôo: {0}", duck.perfomFly());
            Console.WriteLine("Grasnar: {0}", duck.performQuack());



            Console.WriteLine();

            Console.ReadKey();
        }
示例#9
0
        static void Main(string[] args)
        {
            Duck mallard = new MallardDuck();

            mallard.Display();
            mallard.performQuack();
            mallard.performFly();


            Duck model = new ModelDuck();

            model.Display();
            model.performFly();
            model.SetFlyBehavior(new FlyRocketPowered());
            model.performFly();

            Console.WriteLine("The following is a duck call");
            DuckCall duckCall = new DuckCall(new RegularQuack());

            duckCall.Quack();

            Console.ReadLine();
        }
        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();
        }