static void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionDisplay cd = new CurrentConditionDisplay(weatherData); weatherData.setMeasurements(80, 65, 30.4f); weatherData.setMeasurements(82, 70, 29.2f); weatherData.setMeasurements(78, 90, 29.2f); }
static void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionDisplay currentConditionDisplay = new CurrentConditionDisplay(weatherData); weatherData.SetMeasurement(80, 65, 30.4f); weatherData.RegisterObserver(currentConditionDisplay); weatherData.SetMeasurement(80, 65, 30.4f); weatherData.Remove(currentConditionDisplay); weatherData.SetMeasurement(80, 65, 30.4f); }
static void Main(string[] args) { WeatherData weatherData = new WeatherData(); CurrentConditionDisplay currentDisplay = new CurrentConditionDisplay(weatherData); StatisticDisplay statsDisplay = new StatisticDisplay(weatherData); weatherData.SetMeasurements(80, 65, 4f); weatherData.SetMeasurements(82, 70, 29.2f); weatherData.SetMeasurements(78, 90, 29.2f); Console.ReadLine(); }
static void Main(string[] args) { WeatherData weatherData = new WeatherData(); Console.WriteLine("--------公告板1加入观察者-------"); CurrentConditionDisplay display1 = new CurrentConditionDisplay(weatherData); weatherData.SetMessureMents(10, 20, 30); Console.WriteLine("--------公告板2加入观察者-------"); ForecastDisplay display2 = new ForecastDisplay(weatherData); weatherData.SetMessureMents(15, 25, 35); Console.WriteLine("--------公告板1退出观察者-------"); weatherData.RemoveObserver(display1); weatherData.SetMessureMents(19, 29, 39); }
static void Main(string[] args) { var meteostation = new Meteostation(); var weatherData = new WeatherData(meteostation); var currentConditionDisplay = new CurrentConditionDisplay(weatherData); meteostation.mesurementsChanged(); var forecastDisplay = new ForecastDisplay(weatherData); meteostation.mesurementsChanged(); currentConditionDisplay.Unsubscribe(); meteostation.mesurementsChanged(); var statisticsDisplay = new StatisticsDisplay(weatherData); currentConditionDisplay.Subscribe(weatherData); meteostation.mesurementsChanged(); }