public static void Main(string[] args) { WeatherData weatherData = new WeatherData(); //create displays and pass them the WeatherData object CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(); ForecastDisplay forecastDisplay = new ForecastDisplay(); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(); var currentDisplayUnsubscriber = weatherData.Subscribe(currentDisplay); var statisticsDisplayUnsubscriber = weatherData.Subscribe(statisticsDisplay); var forecastDisplayUnsubscriber = weatherData.Subscribe(forecastDisplay); var heatIndexDisplayUnsubscriber = weatherData.Subscribe(heatIndexDisplay); //simulate weather measurements weatherData.setMeasurements(80, 65, 30.4f); weatherData.setMeasurements(82, 70, 29.2f); weatherData.setMeasurements(78, 90, 30.4f); currentDisplayUnsubscriber.Dispose(); statisticsDisplayUnsubscriber.Dispose(); forecastDisplayUnsubscriber.Dispose(); heatIndexDisplayUnsubscriber.Dispose(); Console.ReadLine(); }
public static void Main(string[] args) { //create the subject to be subscribed to WeatherData weatherData = new WeatherData(); //create displays and pass them the subject CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); HeatIndexDisplay heatIndexDisplay = new HeatIndexDisplay(weatherData); //simulate weather measurements weatherData.setMeasurements(80, 65, 30.4f); weatherData.setMeasurements(82, 70, 29.2f); weatherData.setMeasurements(78, 90, 30.4f); Console.ReadLine(); }