首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏编程拯救世界

    《Head First 设计模式》学习笔记 | 观察者模式

    $weatherData */ private $weatherData; public function __construct($weatherData) { // 创建一个 WeatherData 实例 $this->weatherData = $weatherData; $this->weatherData->registerObserver // 创建一个 WeatherData 实例 $this->weatherData = $weatherData; $this->weatherData->registerObserver 对象 $weatherData = new WeatherData(); // 创建显示装置 1,传入 WeatherData 对象 $firstDisplay = new FirstDisplay( $weatherData); // 传入模拟气象数据 $weatherData->setMeasurements(80, 70, 30.4); $weatherData->setMeasurements

    63210发布于 2020-04-14
  • 来自专栏菩提树下的杨过

    (Head First 设计模式)学习笔记(2) --观察者模式(气象站实例)

     = weatherData;             weatherData.RegisterObserver(this);         }         public void Update ;         public StatisticDisplay(Subject weatherData)          {             this.weatherData = (weatherData);             StatisticDisplay statisticDisplay = new StatisticDisplay(weatherData);             weatherData.SetMeasurements(23, 15, 20);             weatherData.SetMeasurements(28, 12 , 25);             weatherData.SetMeasurements(30, 14, 23);             weatherData.SetMeasurements

    66950发布于 2018-01-23
  • 来自专栏运维开发王义杰

    Go:使用观察者模式

    type WeatherData struct { observers []Observer temperature float64 humidity float64 pressure float64 } func NewWeatherData() *WeatherData { return &WeatherData{ observers = append(wd.observers, o) } func (wd *WeatherData) RemoveObserver(o Observer) { wd.observers = (ForecastDisplay).Update = weatherData.RegisterObserver weatherData.SetMeasurements(80, 65, 30.4 ) weatherData.SetMeasurements(82, 70, 29.2) weatherData.SetMeasurements(78, 90, 29.2) } 总结

    31620编辑于 2023-08-10
  • 来自专栏关忆北.

    HTTP对接方式

    =0.06), WeatherData(time=2020-10-05 16:30:00, level=, value=0), WeatherData(time=2020-10-05 16:35:00, 16:45:00, level=, value=0), WeatherData(time=2020-10-05 16:50:00, level=小雨, value=0.04), WeatherData :00, level=, value=0), WeatherData(time=2020-10-05 17:15:00, level=, value=0), WeatherData(time=2020- 10-05 17:20:00, level=, value=0), WeatherData(time=2020-10-05 17:25:00, level=, value=0), WeatherData , value=0.02), WeatherData(time=2020-10-05 17:50:00, level=小雨, value=0.04), WeatherData(time=2020-10-

    1.6K20发布于 2020-10-15
  • 来自专栏程序员小跃

    设计模式之观察者模式(一)

    有一个气象站,由WeatherData对象负责追踪目前的天气情况(温度、湿度、气压)。现在需要建立一个应用,有三种布告板,分别显示目前的状况、气象统计及简单的预报。 image 现在已经提供了WeatherData类,对比刚才的需求,来做进一步的分析。 ? image 我们知道些什么? 一旦WeatherData有新的测量,这些布告必须马上更新 此系统必须可扩展,让其他开发人员建立定制的布告板,用户可以随心所欲地添加或删除任何布告板。 ; public CurrentConditionDisplay(Subject weatherData) { this.weatherData = weatherData; 对象 WeatherData weatherData = new WeatherData(); // 建立布告板,把WeatherData对象传给它们

    56721发布于 2019-12-25
  • 来自专栏架构师进阶

    23种设计模式之观察者模式

    实现 继承Observable,直接实现 public class WeatherData extends Observable { //天气状态 private String state } 测试 public class JDKObserverTest { public static void main(String[] args) { Observable weatherData =new WeatherData(); ObserverHZ hz=new ObserverHZ(); ObserverNJ nj=new ObserverNJ(); weatherData.addObserver(hz); weatherData.addObserver(nj); ((WeatherData) weatherData ).setState("温度29度,湿度30\""); //((WeatherData) weatherData).setChanged(); //weatherData.notifyObservers

    45630发布于 2019-08-08
  • 来自专栏BaronTalk

    观察者模式(ObserverPattern)

    概况 这套系统中主要包括三个部分:气象站(获取天气数据的物理设备)、WeatherData(追踪来自气象站的数据,并更新公告牌)、公告牌(用于展示天气数据) WeatherData知道如何跟气象站联系, 当天气数据有更新时,WeatherData会更新两个公告牌用于展示新的天气数据。 ;//气压 public CurrentConditionsDisplay(WeatherData weatherData) { this.weatherData = weatherData weatherData) { this.weatherData = weatherData; this.weatherData.registerObserver(this (weatherData); ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData); List

    756100发布于 2018-04-13
  • 来自专栏运维开发王义杰

    使用Go语言实现观察者模式

    pressure float64 } func NewWeatherData() *WeatherData { return &WeatherData{} } func (w *WeatherData) RegisterObserver(o Observer) { w.observers = append(w.observers, o) } func (w *WeatherData = &CurrentConditionsDisplay{weatherData: weatherData} weatherData.RegisterObserver(c) return := NewWeatherData() NewCurrentConditionsDisplay(weatherData) weatherData.SetMeasurements(80 , 65, 30.4) weatherData.SetMeasurements(82, 70, 29.2) weatherData.SetMeasurements(78, 90, 29.2

    36420编辑于 2023-08-10
  • 来自专栏技术赋能学术

    Head First设计模式——观察者模式

    ; public CurrentConditionDisply(Subject weatherData) { this.weatherData = ; public StaisticsDisply(Subject weatherData) { this.weatherData = weatherData ; public ForcastDisply(Subject weatherData) { this.weatherData = weatherData static void Main(string[] args) { WeatherData weatherData = new WeatherData(); = new ForcastDisply(weatherData); weatherData.SetMeasurments(30, 65, 30.5F);

    80030发布于 2020-08-11
  • 来自专栏码上遇见你

    观察者模式

    并将 接入方 currentConditions 传递到 WeatherDataWeatherData weatherData = new WeatherData(currentConditions WeatherData weatherData = new WeatherData(); //创建观察者 CurrentConditions currentConditions = new CurrentConditions(); //注册到weatherData weatherData.registerObserver(currentConditions); weatherData.registerObserver WeatherData weatherData = new WeatherData(); //创建观察者 CurrentConditions currentConditions = , 看看信息"); weatherData.setData(10f, 100f, 30.3f); // 删除操作 weatherData.removeObserver(currentConditions

    27720编辑于 2023-06-28
  • 来自专栏InvQ的专栏

    观察者(Observer)模式

    ) { weatherData.registerObserver(this); } @Override public void update(float temp ) { weatherData.registerObserver(this); } @Override public void update(float temp weatherData = new WeatherData(); CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay (weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); weatherData.setMeasurements(0, 0, 0); weatherData.setMeasurements(1, 1, 1); } } CurrentConditionsDisplay.update

    50110编辑于 2022-05-06
  • 来自专栏繁依Fanyi 的专栏

    Flutter开发多端天气预报App:一场奇妙的编程之旅

    weatherData["daily"][0]["precip"] + " mm"; weatherDay1['Pressure'] = weatherData["daily"][0][ '] = weatherData["daily"][2]["tempMax"] + " °C"; weatherDay3['Humidity'] = weatherData["daily Sunset'] = weatherData["daily"][2]["sunset"]; weatherDay3['Condition'] = weatherData["daily"] weatherData["daily"][0]["precip"] + " mm"; weatherDay1['Pressure'] = weatherData["daily"][0][ '] = weatherData["daily"][2]["tempMax"] + " °C"; weatherDay3['Humidity'] = weatherData["daily

    66430编辑于 2024-03-20
  • 来自专栏JMCui

    观察者模式.

    ) { WeatherData weatherData = (WeatherData) o; Float humidity = weatherData.getHumidity ) { WeatherData weatherData = (WeatherData) o; Float pressure = weatherData.getPressure ) { WeatherData weatherData = (WeatherData) o; Float temperature = weatherData.getTemperature weatherData = new WeatherData(24.0F,152F,100F); // 观察者订阅 new HumidityObserver(weatherData); new PressureObserver(weatherData); new TemperatureObserver(weatherData); // 事件发生 weatherData.measurementsChanged

    66910发布于 2018-12-11
  • 来自专栏Ryan Miao

    java设计模式(六)--观察者模式

    ; public CurrentConditionsDisplay(Subject weatherData) { this.weatherData = weatherData; weatherData = new WeatherData(); CurrentConditionsDisplay currentDisplay = new (weatherData); weatherData.setMeasurements(80, 65, 30.4f); weatherData.setMeasurements ) { WeatherData weatherData = (WeatherData)obs; this.temperature = weatherData.getTemperature (weatherData,forecastDisplay); currentDisplay.update(weatherData,forecastDisplay); weatherData.setMeasurements

    1.2K100发布于 2018-03-13
  • 来自专栏Java啊

    Java设计模式之观察者模式

    并将 接入方 currentConditions 传递到 WeatherDataWeatherData weatherData = new WeatherData(currentConditions 当数据有更新时,就主动的调用 ArrayList, 通知所有的(接入方)就看到最新的信息 */ public class WeatherData implements Subject { WeatherData weatherData = new WeatherData(); //创建观察者 CurrentConditions currentConditions weatherData.registerObserver(currentConditions); weatherData.registerObserver(baiduSite 这样,我们增加观察者(这里可以理解成一个新的公告板),就不需要去修改核心类WeatherData不会修改代码,遵守了ocp原则。

    39130编辑于 2022-12-27
  • Flutter 开发多端天气预报App:一场奇妙的编程之旅

    weatherDay1['Sunrise'] = weatherData["daily"][0]["sunrise"]; weatherDay1['Sunset'] = weatherData = weatherData["daily"][1]["textDay"]; weatherDay2['UV Index'] = weatherData["daily"][1]["uvIndex weatherDay3['Sunrise'] = weatherData["daily"][2]["sunrise"]; weatherDay3['Sunset'] = weatherData weatherDay1['Sunrise'] = weatherData["daily"][0]["sunrise"]; weatherDay1['Sunset'] = weatherData weatherDay3['Sunrise'] = weatherData["daily"][2]["sunrise"]; weatherDay3['Sunset'] = weatherData

    97211编辑于 2024-01-18
  • 来自专栏海仔技术驿站

    图解Java设计模式之观察者模式

    天气预报设计方案 1 - 普通方案 通过对气象站项目的分析,设计出一个WeatherData类 ? 说明 : 1)通过getXxx方法,可以让第三方接入,并得到相关信息。 并将 接入方 currentConditions 传递到 WeatherDataWeatherData weatherData = new WeatherData(currentConditions WeatherData weatherData = new WeatherData(); // 创建观察者 CurrentConditions currentConditions = new CurrentConditions(); BaiduSite baiduSite = new BaiduSite(); // 注册到weatherData weatherData.registerObserver 2)这样,我们增加观察者(可以理解为一个新的公告板),就不需要去修改核心类WeatherData不会修改代码,遵守类ocp原则。 观察者模式在JDK应用的源码分析 ? ? ?

    54120发布于 2020-04-02
  • 来自专栏java学习java

    观察者模式解读

    并将 接入方 currentConditions 传递到 WeatherDataWeatherData weatherData = new WeatherData(currentConditions 2) 无法在运行时动态的添加第三方 (新浪网站) 3) 违反 ocp 原则=>观察者模式 //在 WeatherData 中,当增加一个第三方,都需要创建一个对应的第三方的公告板对象,并加入到 WeatherData weatherData = new WeatherData(); //创建观察者 CurrentConditions currentConditions weatherData.registerObserver(currentConditions); weatherData.registerObserver(baiduSite 2) 这样,我们增加观察者(这里可以理解成一个新的公告板),就不需要去修改核心类 WeatherData 不会修改代码,遵守了 ocp 原则

    27940编辑于 2023-10-15
  • 来自专栏程序员奇点

    设计模式-观察者模式

    ) { weatherData.reisterObserver(this); } @Override public void update(float temp ) { weatherData.registerObserver(this); } @Override public void update(float temp weatherData = new WeatherData(); CurrentConditionsDisplay currentConditionsDisplay = new CurrentConditionsDisplay (weatherData); StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData); weatherData.setMeasurements(0, 0, 0); weatherData.setMeasurements(1, 1, 1); } } Java 中有哪些类用了观察者模式

    59510发布于 2020-11-11
  • 设计模式:观察者模式

    = new WeatherData(); CurrentConditionsDisplay display = new CurrentConditionsDisplay(weatherData ); weatherData.setMeasurements(25.5f, 65, 1013.1f); weatherData.setMeasurements ; public CurrentConditionsDisplay(Subject weatherData) { this.weatherData = weatherData; = weatherData.getTemperature(); this.humidity = weatherData.getHumidity(); display(); ) { // 拉取数据 WeatherData wd = (WeatherData) o; // 或使用arg参数获取推送数据

    35210编辑于 2025-03-11
领券