Ejemplo n.º 1
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);

            Measurements measurements = new Measurements
            {
                humidity    = 65F,
                pressure    = 30.4F,
                temperature = 80F
            };

            weatherData.SetMeasurements(measurements);

            measurements.humidity    = 70F;
            measurements.pressure    = 29.2F;
            measurements.temperature = 82F;
            weatherData.SetMeasurements(measurements);

            measurements.humidity    = 90F;
            measurements.pressure    = 29.2F;
            measurements.temperature = 78F;
            weatherData.SetMeasurements(measurements);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Observer demo:");
            WeatherData weatherData           = new WeatherData();
            CurrentConditionsDisplay display1 = new CurrentConditionsDisplay(weatherData);

            weatherData.RegisterObserver(display1);
            weatherData.SetMeasurements(20.3f, 50, 12);
            weatherData.SetMeasurements(23.1f, 55, 17);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 31.4f);
            weatherData.SetMeasurements(78, 90, 29.2f);
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);

            Console.ReadLine();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var weather  = new WeatherData();
            var observer = new CurrentConditionsDisplay(weather);

            //其他观察者
            //
            weather.setMeasurements(3, 4, 6);
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Observer started v1.0!");
            Console.WriteLine("Created by @echoladone");

            var weatherData    = new WeatherData();
            var currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.setMeasurements(80, 65, 30.4f);
            weatherData.setMeasurements(82, 70, 29.8f);
            weatherData.setMeasurements(78, 90, 29.2f);
        }
Ejemplo n.º 7
0
 static void Main(string[] args)
 {
     WeatherData weatherData = new WeatherData();
     CurrentConditionsDisplay ccd = new CurrentConditionsDisplay(weatherData);
     ForecastDisplay fd = new ForecastDisplay(weatherData);
     StatisticsDisplay sd = new StatisticsDisplay(weatherData);
     ThirdPartyDisplay tpd = new ThirdPartyDisplay(weatherData);
     weatherData.SetMeasurements(15, 75, 30);
     weatherData.SetMeasurements(18, 80, 31.2);
     weatherData.SetMeasurements(18, 75, 32.8);
     Console.ReadKey(true);
 }
Ejemplo n.º 8
0
        static void Main()
        {
            WeatherData wd = new WeatherData();
            CurrentConditionsDisplay ccd = new CurrentConditionsDisplay(wd);
            StatisticsDisplay sd = new StatisticsDisplay(wd);
            HeatIndexDisplay hid = new HeatIndexDisplay(wd);

            wd.SetMeasurements(78, 90, 29.2f);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.SetMeasureemnts(80, 65, 30.4f);
            Thread.Sleep(1000);
            weatherData.SetMeasureemnts(82, 70, 29.2f);
            Thread.Sleep(1500);
            weatherData.SetMeasureemnts(78, 90, 29.2f);

            Console.ReadLine();
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            //StatisticsDisplay currentDisplay = new StatisticsDisplay(weatherData);
            //ForecastDisplay currentDisplay = new ForecastDisplay(weatherData);

            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(82, 70, 29.4f);
            weatherData.SetMeasurements(78, 90, 29.4f);
        }
Ejemplo n.º 11
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.setMeasurements(80, 65, 30.4f);
            weatherData.setMeasurements(82, 70, 29.2f);
            weatherData.setMeasurements(78, 90, 29.2f);
        }
Ejemplo n.º 12
0
        public void Main()
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay        = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay          = new ForecastDisplay(weatherData);
            HeatIndexDisplay         heatIndexDisplay         = new HeatIndexDisplay(weatherData);

            weatherData.SetMeasurementsChanged(80, 65, 30.4f);
            Console.WriteLine("===========================================");
            weatherData.SetMeasurementsChanged(82, 70, 29.2f);
            Console.WriteLine("===========================================");
            weatherData.SetMeasurementsChanged(78, 90, 29.2f);
        }
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();

            //Инициализация наблюдателей
            CurrentConditionsDisplay currentDisplay    = new CurrentConditionsDisplay(weatherData);
            StatisticsDisplay        statisticsDisplay = new StatisticsDisplay(weatherData);
            ForecastDisplay          forecastDisplay   = new ForecastDisplay(weatherData);

            //Обновление данных
            weatherData.setMeasurements(80, 45, 34.5f);
            //Удаление одного из наблюдателей
            statisticsDisplay.remove();
            weatherData.setMeasurements(45, 34, 37.6f);
            weatherData.setMeasurements(49, 45, 38.5f);
        }
Ejemplo n.º 14
0
        public static void Main(string[] args)
        {
/*          Primero crearemos una instancia de los datos de la estación meteorológica,
 *          que es donde se mantienen registrados los observadores que desean ver su
 *          información.
 *
 *          Entra a la clase WeatherData para verlo más a detalle y
 *          despues analiza la clase CurrentConditionsDisplay para ver
 *          como es el proceso de subscripcion */
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay =
                new CurrentConditionsDisplay(weatherData);

            //para poder observar los resultados asignamos y cabiamos los valores en las
            //mediciones de la estacion
            weatherData.SetMeasurements(80, 65, 30.4f);
            weatherData.SetMeasurements(85, 70, 35.4f);
            weatherData.SetMeasurements(89, 75, 40.4f);
            Console.ReadLine();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Weather Station");
            Console.WriteLine();

            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.SetMeasurements(80, 65, 30.4f);
            Console.WriteLine();
            weatherData.SetMeasurements(87, 70, 29.2f);
            Console.WriteLine();
            weatherData.SetMeasurements(78, 90, 29.2f);
            Console.WriteLine();
            weatherData.SetMeasurements(65, 75, 29.2f);
            Console.WriteLine();

            int   temp, hum;
            float press;

            Console.Write("What is the current Temperature? T: ");
            temp = Int32.Parse(Console.ReadLine());
            Console.Write("What is the current Humidity? H: ");
            hum = Int32.Parse(Console.ReadLine());
            Console.Write("What is the current Pressure? P: ");
            press = float.Parse(Console.ReadLine());
            Console.WriteLine();

            weatherData.SetMeasurements(temp, hum, press);
            Console.WriteLine();

            Console.ReadKey();
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            /*
             * The Observer Pattern
             *
             * Example:
             * A publisher creates a new magazine and begins publishing issues.
             * You subscribve and receive issues as along as you stay subscribed.
             * You can unsubscribe at any time.
             * Others can also subscribe.
             * Other can also unsubscribe.
             * If Publisher ceases business, you stop receiving issues.
             *
             * Allows:
             * -Subjests and Observers are "loosely coupled"
             * -Strive for loosely coupled designs between objects that interact. (Design Principle #4)
             *
             * Implementation (Push):
             *
             * We define 3 interfaces:
             *  -ISubject (implemented by publisher, stores the list of subscribers, notifies on updates)
             *  -IObserver (implemented by subscriber, update method)
             *  -IDisplayElement (implemented by subscriber, display method)
             *
             * We define main class WatherData:
             *  -WatherData that implements ISubject
             *  -Notifies observers(subscribers) though method Update()
             *  -This doesn't know anything about observers
             *  -Subject doesn't care it keeps doing its job
             *
             * We define subscriber classes:
             * -Each implements interfaces IObserver and IDisplayElement just to display info
             * -Each receives Subject(Publisher) in constructor, subscribes itself to it, and keeps it in private field
             * -To become an observer it needs to implement IObserver
             *
             */

            //create concrete subject(publisher)
            WeatherData weatherData = new WeatherData();

            //create Observer(subscriber) and register with Subject(publisher)
            CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData); //subscribe in constructor of observer(subscriber), PUSH subscription

            //create more Observers(subscribers)
            weatherData.RegisterObserver(new StatisticsDisplay(weatherData)); //subscribe in method of subject(publisher), PULL subscription

            ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData);

            //refresh data at Subject(publisher), simulate new data from sensors
            weatherData.SetMeasurements(new Data()
            {
                Temp     = 80,
                Humidity = 65,
                Pressure = 29.2
            });

            weatherData.SetMeasurements(new Data()
            {
                Temp     = 82,
                Humidity = 70,
                Pressure = 30.4
            });

            weatherData.SetMeasurements(new Data()
            {
                Temp     = 78,
                Humidity = 90,
                Pressure = 29.4
            });

            Console.ReadLine();
        }
Ejemplo n.º 17
0
 static void Main(string[] args)
 {
     var weather = new WeatherData();
     var observer = new CurrentConditionsDisplay(weather);
     //其他观察者
     //
     weather.setMeasurements(3, 4, 6);
     Console.ReadKey();
 }