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

            weatherData.SetMeasurementData(1, 2, 3);

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

            weatherData.SetMeasurementData(6, 6, 6);
        }
        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();
        }
Beispiel #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);
        }