public static void Run(string[] args) { Duck mallard = new MallardDuck(); mallard.performQuack(); mallard.performFly(); }
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(); }
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(); */ }
public static void Test() { Duck mallard = new MallardDuck(); mallard.performQuack(); mallard.performFly(); Duck model = new ModelDuck(); model.performFly(); model.setFlyBehavior(new FlyRocketPowered()); model.performFly(); }
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(); }
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(); }
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(); }