/// <summary> /// Tests the observer pattern implementation. /// </summary> /// <param name="args">Cmdline input arguments.</param> static void Main(string[] args) { // Initialize the weather. var latestWeather = new WeatherDataObject(-1, -1, -1); // Initialize the observers. var currentDisplay = new CurrentConditionsDisplay(); var statisticsDisplay = new StatisticsDisplay(); var forecastDisplay = new ForecastDisplay(); var initialObserverList = new ArrayList { currentDisplay, statisticsDisplay, forecastDisplay }; // Initialize the weather provider. var defaultORamaWeatherProvider = new DefaultORamaWeatherProvider(initialObserverList, latestWeather); // Trigger the measurements changed function. defaultORamaWeatherProvider.MeasurementsChanged(); // Update the data. defaultORamaWeatherProvider.SetMeasurements(new WeatherDataObject(25, 60, 0.78)); // Remove the forecast device. defaultORamaWeatherProvider.RemoveObserver(forecastDisplay); // Update the data. defaultORamaWeatherProvider.SetMeasurements(new WeatherDataObject(15, 50, 0.68)); }
/// <summary> /// Displays the data to the screen. /// </summary> public void Display() { CurrentConditionsDisplay.DisplayEachData("FC_Temperature", _latestWeatherData.Temperature); CurrentConditionsDisplay.DisplayEachData("FC_Humidity", _latestWeatherData.Humidity); CurrentConditionsDisplay.DisplayEachData("FC_Pressure", _latestWeatherData.Pressure); CurrentConditionsDisplay.DisplayEachData("FC_HeatIndex", _latestWeatherData.HeatIndex); }
static void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); weatherData.setMeasurements(80, 65, 30.4f); weatherData.setMeasurements(82, 70, 29.2f); weatherData.setMeasurements(78, 90, 29.2f); Console.ReadKey(); }