1 Star 0 Fork 0

彭冠铭/JavaSe

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ConcreateWeaSubject.java 925 Bytes
一键复制 编辑 原始数据 按行查看 历史
彭冠铭 提交于 2018-04-16 22:36 +08:00 . first commit
package Observer.weather;
/**
* 具体目标对象(天气预报),负责把有关状态存入到相应的观察者对象中
*/
public class ConcreateWeaSubject extends WeaSubject {
// 晴天,下雪,下雨
private String weatherContent;
public String getWeatherContent() {
return weatherContent;
}
public void setWeatherContent(String weatherContent) {
this.weatherContent = weatherContent;
// 内容有了,说明内容更新,通知所有订阅天气的人
this.notifyObsservers(weatherContent);
}
// 区别对待观察者
@Override
protected void notifyObsservers(String content) {
for (Obs o : observers) {
if ("下雨".equals(this.getWeatherContent())) {
if ("范冰冰".equals(o.getObseverName())) {
o.update(this);
}
if ("我的老妈".equals(o.getObseverName())) {
o.update(this);
}
}
if ("下雪".equals(this.getWeatherContent())) {
if ("我的老妈".equals(o.getObseverName())) {
o.update(this);
}
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/pgm250/JavaSe.git
git@gitee.com:pgm250/JavaSe.git
pgm250
JavaSe
JavaSe
master

搜索帮助