Пример #1
0
        static void Main(string[] args)
        {
            WeatherData               weatherData               = new WeatherData();
            CurrentPressureDisplay    currentPressureDisplay    = new CurrentPressureDisplay();
            CurrentHumidityDisplay    currentHumidityDisplay    = new CurrentHumidityDisplay();
            CurrentTemperatureDisplay currentTemperatureDisplay = new CurrentTemperatureDisplay();
            CurrentWeatherDisplay     currentWeatherDisplay     = new CurrentWeatherDisplay();

            weatherData.RegisterObserver(currentPressureDisplay);
            weatherData.RegisterObserver(currentHumidityDisplay);
            weatherData.RegisterObserver(currentTemperatureDisplay);
            weatherData.RegisterObserver(currentWeatherDisplay);

            weatherData.SetMeasurementData(1, 2, 3);

            weatherData.RemoveObserver(currentHumidityDisplay);
            weatherData.RemoveObserver(currentTemperatureDisplay);

            weatherData.SetMeasurementData(6, 6, 6);
        }
Пример #2
0
        static void Main(string[] args)
        {
            WeatherData weatherData = new WeatherData();
            CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);

            weatherData.RegisterObserver(currentDisplay);

            weatherData.SetMeasurements(80, 65, 30.4);
            weatherData.SetMeasurements(82, 70, 29.2);
            weatherData.SetMeasurements(78, 90, 29.2);

            Console.ReadKey();
        }
Пример #3
0
        public void UnitTest()
        {
            IDataProvider dataProvider = new DataProvider(32, 102, 30);

            ISubject subject = new WeatherData(dataProvider);

            IOberserver o1 = new Observer1();
            IOberserver o2 = new Observer2();
            IOberserver o3 = new Observer3();

            subject.RegisterObserver(o1);
            subject.RegisterObserver(o2);
            subject.RegisterObserver(o3);

            dataProvider.ChangeTemperature(36);
            dataProvider.ChangePressure(110);
            dataProvider.ChangeTemperature(80);

            subject.RemoveObserver(o3);


            dataProvider.ChangeTemperature(31);
        }
Пример #4
0
        static void Main(string[] args)
        {
            WeatherData            weatherData            = new WeatherData();
            CurrentConditionDisply currentConditionDisply = new CurrentConditionDisply(weatherData);
            StaisticsDisply        staisticsDisply        = new StaisticsDisply(weatherData);
            ForcastDisply          forcastDisply          = new ForcastDisply(weatherData);

            weatherData.SetMeasurments(30, 65, 30.5F);
            Console.WriteLine("---------------移除订阅者-----------");
            weatherData.RemoveObserver(currentConditionDisply);
            weatherData.SetMeasurments(31, 55, 20);
            Console.WriteLine("---------------添加订阅者-----------");
            weatherData.RegisterObserver(currentConditionDisply);
            weatherData.SetMeasurments(30, 55, 30.5F);
            Console.ReadKey();
        }
Пример #5
0
 public ForecastDisplay(WeatherData weatherData)
 {
     WeatherData = weatherData;
     weatherData.RegisterObserver(this);
 }
 public StatisticsDisplay(WeatherData weatherData)
 {
     this.weatherData = weatherData;
     weatherData.RegisterObserver(this);
 }
Пример #7
0
 public StatisticsDisplay(WeatherData weatherData) {
     weatherData.RegisterObserver(this);
     history = new List<float>();
 }
Пример #8
0
 public StatisticsDisplay(WeatherData weatherData)
 {
     weatherData.RegisterObserver(this);
     history = new List <float>();
 }