Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
 public void Update(object latestDataObject)
 {
     // Explicitly cast the generic 'object' data type to WeatherDataObject.
     // This is to support the IObserver's generic 'Update' method.
     _latestWeatherData = (WeatherDataObject)latestDataObject;
     Display();
 }
Exemplo n.º 3
0
 /// <summary>
 /// A test hook to support the update of weather data.
 /// </summary>
 /// <param name="newWeatherData">The new data that will be passed to the observers.</param>
 public void SetMeasurements(WeatherDataObject newWeatherData)
 {
     _latestWeatherDataObject = newWeatherData;
     MeasurementsChanged();
 }
Exemplo n.º 4
0
 public DefaultORamaWeatherProvider(ArrayList initialListOfRegisteredDataObjects,
                                    WeatherDataObject initialWeatherDataObject)
 {
     RegisteredWeatherDataObjects = initialListOfRegisteredDataObjects;
     _latestWeatherDataObject     = initialWeatherDataObject;
 }
Exemplo n.º 5
0
 public DefaultORamaWeatherProvider()
 {
     RegisteredWeatherDataObjects = new ArrayList();
     _latestWeatherDataObject     = new WeatherDataObject();
 }