Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var weatherData = new WeatherData();
            var currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);
            var weatherStatisticsDisplay = new WeatherStatisticsDisplay(weatherData);

            weatherData.SetWeatherData(20.0f, 30.0f, 40.0f);
            weatherData.SetWeatherData(80.0f, 85.0f, 90.0f);
        }
Ejemplo n.º 2
0
        public static void UseObserverPattern(IView view)
        {
            //Subject
            WeatherData weatherData = new WeatherData();

            //create and add one observer
            IObserver currentConditions = new CurrentConditionsDisplay(view, weatherData);

            weatherData.SetMeasurements(20.1f, 87, 1100);

            currentConditions.Unregister();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay  = new HeatIndexDisplay(weatherData);

            weatherData.SetMesurements(80, 65, 30.4f);
            weatherData.SetMesurements(82, 70, 29.2f);
            weatherData.SetMesurements(78, 90, 29.2f);

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        public static void Observer()
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay =
                new CurrentConditionsDisplay(weatherData);

            // StatisticsDisplay staticsDisplay = new StatisticsDisplay(weatherData);
            // ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData);

            weatherData.setMeasurements(80, 65, 30.4f);
            weatherData.setMeasurements(82, 70, 29.2f);
            weatherData.setMeasurements(78, 90, 29.2f);
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            #region Using ObserverPattern
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay display = new CurrentConditionsDisplay(weatherData);
            weatherData.setMeasurements(80, 65, 30.4f);
            weatherData.setMeasurements(82, 70, 29.2f);
            weatherData.setMeasurements(78, 90, 29.2f);
            #endregion

            #region Using Strategy pattern
            Duck duck = new Duck();
            duck.setFlyBehavior(new FlyWithWings());
            duck.setQuackBehavior(new Quack());
            duck.performFly();
            duck.performQuack();

            Duck duck2 = new Duck();
            duck2.setFlyBehavior(new FlyWithWings());
            duck2.setQuackBehavior(new Squeakcs());
            duck2.performQuack();
            duck2.performFly();
            #endregion

            #region Using Decorator pattern
            Beverage beverage = new Espresso();
            Console.WriteLine(beverage.GetDescription() + " $" + beverage.cost());

            Beverage beverage2 = new DarkRoast();
            beverage2 = new Mocha(beverage2);
            beverage2 = new Mocha(beverage2);
            beverage2 = new Whip(beverage2);
            Console.WriteLine(beverage2.GetDescription() + " $" + beverage2.cost());

            Beverage beverage3 = new HouseBlend();
            beverage3 = new Soy(beverage3);
            beverage3 = new Mocha(beverage3);
            beverage3 = new Whip(beverage3);
            Console.WriteLine(beverage3.GetDescription() + " $" + beverage3.cost());
            #endregion

            // Don't close console on program end
            Console.ReadKey();
        }