コード例 #1
0
        private void RunObserverPatternExample()
        {
            var weather   = new WeatherData();
            var observers = new IWeatherObserver[2];

            observers[0] = new CurrentWeatherDisplay();
            observers[1] = new ForecastDisplay();

            foreach (IWeatherObserver weatherObserver in observers)
            {
                weather.WeatherNotification += weatherObserver.UpdateWeatherDate;
            }

            weather.ChangeWeatherData();
            DisplayHumidityInListBox(observers);

            weather.ChangeWeatherData();
            DisplayHumidityInListBox(observers);
        }