static void Main(string[] args) { // create the subject and observers WeatherData weatherData = new WeatherData(); CurrentConditions conditions = new CurrentConditions(weatherData); Statistics statistics = new Statistics(weatherData); Forecast forecast = new Forecast(weatherData); Piano piano = new Piano(weatherData); // create the readings WeatherMeasurements readings = new WeatherMeasurements(); readings.humidity = 40.5F; readings.pressure = 20F; readings.temperature = 72F; // update the readings - everyone should print weatherData.UpdateReadings(readings); // update readings.pressure = 10F; weatherData.UpdateReadings(readings); // update readings.humidity = 100; readings.temperature = 212.75F; readings.pressure = 950; weatherData.UpdateReadings(readings); Console.ReadLine(); }
public void Update(object subject, WeatherMeasurements newReadings) { if (subject is WeatherData) { this.readings = newReadings; Display(); } }
public void UpdateReadings(WeatherMeasurements newReadings) { this.readings = newReadings; Change(); }