package cn.bunny.pattern3.demo1;


import cn.bunny.pattern3.demo1.observer.Observer;
import cn.bunny.pattern3.demo1.observer.Observer1;
import cn.bunny.pattern3.demo1.observer.Observer2;
import cn.bunny.pattern3.demo1.observer.Observer3;
import cn.bunny.pattern3.demo1.subject.WeatherStationSubject;

public class Main {
    public static void main(String[] args) {
        WeatherStationSubject weatherStationSubject = new WeatherStationSubject();
        Observer observer1 = new Observer1();
        Observer observer2 = new Observer2();
        Observer observer3 = new Observer3();

        // 注册观察者
        weatherStationSubject.registerObserver(observer1);
        weatherStationSubject.registerObserver(observer2);
        weatherStationSubject.registerObserver(observer3);

        // 更新天气温度，观察者会收到通知
        weatherStationSubject.setTemperature(25.0f, 25.0f, 25.0f);
        weatherStationSubject.setTemperature(30.0f, 30.0f, 30.0f);

        // 移出观察者1
        weatherStationSubject.removeObserver(observer1);

        // 更新天气温度，观察者会收到通知
        System.out.println("--------------------------");
        weatherStationSubject.setTemperature(44.0f, 44.0f, 44.0f);
    }
}
