-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWeatherStation.java
More file actions
37 lines (28 loc) · 1.06 KB
/
WeatherStation.java
File metadata and controls
37 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package observer;
import observer.impl.CurrentConditionsDisplay;
import observer.impl.ForecastDisplay;
import observer.impl.StatisticsDisplay;
import observer.impl.WeatherData;
/**
* Created by http://teachcourse.cn on 2018/03/22.
*/
public class WeatherStation {
public static void main(String[] args) {
WeatherData weatherData = new WeatherData();
CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(
weatherData);
StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData);
ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData);
//移除掉已注册的观察者
weatherData.removeObserver(currentDisplay);
weatherData.removeObserver(statisticsDisplay);
weatherData.removeObserver(forecastDisplay);
// 重新注册观察者
weatherData.registerObserver(currentDisplay);
weatherData.registerObserver(statisticsDisplay);
weatherData.registerObserver(forecastDisplay);
weatherData.setMeasurements(80, 65, 30.4f);
weatherData.setMeasurements(82, 70, 29.2f);
weatherData.setMeasurements(78, 90, 29.2f);
}
}