Datasets:

ArXiv:
License:
File size: 845 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
package weatherstationex;

/**
 * Created by Administrator on 2017/6/14.
 */
public class CurrentConditionDisplay implements Observer, DisplayElement
{
    private float temperature;
    private float humidity;
    private Subject weatherData;

    public CurrentConditionDisplay(Subject weatherData)
    {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    @Override
    public void update(float temperature, float humidity, float pressure)
    {
        this.temperature = temperature;
        this.humidity = humidity;
        display();
    }

    @Override
    public void display()
    {
        System.out.println(toString());
    }

    @Override
    public String toString()
    {
        return "使用自建观察者模式"+"temperature=" + temperature + ", humidity=" + humidity ;
    }
}