当前位置: 首页 > news >正文

织梦网站模板安装本地查询关键词

织梦网站模板安装本地,查询关键词,关于建设信息网站的请示,资料下载网站建设一、前言 观察者模式,又称为发布订阅模式,是一种行为设置模式,允许对象之间建立一对多的依赖关系,这样当一个对象状态改变时,它的所有依赖者(观察者)都会收到通知并自动更新。 二、具体实现 …

一、前言

观察者模式,又称为发布订阅模式,是一种行为设置模式,允许对象之间建立一对多的依赖关系,这样当一个对象状态改变时,它的所有依赖者(观察者)都会收到通知并自动更新。

二、具体实现

1、发布订阅案例

观察者接口:

/*** @Description: 观察者接口* @Date: 2024-12-27 10:08* @Author: gaoyufei**/
public interface Observer {void accept(String message);
}

观察者实现:

/*** @Description: 订阅者* @Date: 2024-12-27 10:10* @Author: gaoyufei**/
public class Subscriber implements Observer{public String clientId;public Subscriber(String clientId){this.clientId=clientId;}@Overridepublic void accept(String message) {System.out.println("订阅者:"+clientId+" 接受到消息:"+message);}
}

主题接口:

/*** @Description: 主题接口* @Date: 2024-12-27 10:15* @Author: gaoyufei**/
public interface Subject {void add(Observer observer);void del(Observer observer);void notify(String message);
}

主题实现:

import java.util.ArrayList;
import java.util.List;/*** @Description: 主题,维护了订阅者列表,通知订阅者* @Date: 2024-12-27 10:16* @Author: gaoyufei**/
public class Topic implements Subject {private List<Observer> observerList=new ArrayList<>();@Overridepublic void add(Observer observer) {observerList.add(observer);}@Overridepublic void del(Observer observer) {observerList.remove(observer);}@Overridepublic void notify(String message) {observerList.stream().forEach(e->{e.accept(message);});}
}

模拟订阅者订阅主题,客户端发布消息:

/*** @Description: 模拟订阅者订阅主题,客户端发布消息* @Date: 2024-12-27 10:18* @Author: gaoyufei**/
public class Client {public static void main(String[] args) {Topic topic=new Topic();Subscriber subscriber1=new Subscriber("001");Subscriber subscriber2=new Subscriber("002");Subscriber subscriber3=new Subscriber("003");topic.add(subscriber1);topic.add(subscriber2);topic.add(subscriber3);topic.notify("您有一条新消息!");}
}

2、村长通知村民案例

观察者接口:

/*** @Description: 观察者接口* @Date: 2024-12-27 9:35* @Author: gaoyufei**/
public interface Observer {void accept(String message);
}

观察者具体观察者村民:

/*** @Description: 具体观察者,村民,能接受消息* @Date: 2024-12-27 9:37* @Author: gaoyufei**/
public class Resident implements Observer{private String name;public Resident(String name){this.name=name;}@Overridepublic void accept(String message) {System.out.println("村民:"+this.name+"  收到信息:"+message);}
}

抽象主题:

/*** @Description: 抽象主题* @Date: 2024-12-27 9:39* @Author: gaoyufei**/
public interface Subject {void add(Observer observer);void del(Observer observer);void notify(String message);
}

主题的具体实现,村长的记录本:

import java.util.ArrayList;
import java.util.List;
/*** @Description: 主题的具体实现,村长的记录本,维护了村民信息,村长可以通过记录本给村民群发信息* @Date: 2024-12-27 9:42* @Author: gaoyufei**/
public class RecordBook implements Subject {private List<Observer> observerList = new ArrayList<>();@Overridepublic void add(Observer observer) {observerList.add(observer);}@Overridepublic void del(Observer observer) {observerList.remove(observer);}@Overridepublic void notify(String message) {observerList.stream().forEach(e -> {e.accept(message);});}
}

村长登记村民信息,用记录本给村民群发信息:

/*** @Description: 村长登记村民信息,用记录本给村民群发信息* @Date: 2024-12-27 9:44* @Author: gaoyufei**/
public class VillageHead {public static void main(String[] args) {
//        1、村里,村长有一个记录村民电话的本子,村民都需要登记一下。
//        在村里有什么事情的时候,村长就通过群发消息的方式通知村民。
//        2、村民就是观察者、订阅者,村长发布信息,记录本就是主题,RecordBook recordBook=new RecordBook();Resident resident=new Resident("王满银");Resident resident1=new Resident("孙玉亭");Resident resident2=new Resident("孙玉厚");recordBook.add(resident);recordBook.add(resident1);recordBook.add(resident2);recordBook.notify("大家好,今天下午三点来村支部开会,有重要事情通知!");}
}

文章转载自:
http://offering.Lnnc.cn
http://hymeneal.Lnnc.cn
http://thermionic.Lnnc.cn
http://unimodular.Lnnc.cn
http://albeit.Lnnc.cn
http://alamode.Lnnc.cn
http://barracks.Lnnc.cn
http://tog.Lnnc.cn
http://flextime.Lnnc.cn
http://bilharziasis.Lnnc.cn
http://anthropological.Lnnc.cn
http://putridly.Lnnc.cn
http://oleoresin.Lnnc.cn
http://rivalrous.Lnnc.cn
http://illogicality.Lnnc.cn
http://indemnificatory.Lnnc.cn
http://circumnavigation.Lnnc.cn
http://footwall.Lnnc.cn
http://exodontia.Lnnc.cn
http://cephalic.Lnnc.cn
http://industrialisation.Lnnc.cn
http://rudy.Lnnc.cn
http://tempered.Lnnc.cn
http://pedate.Lnnc.cn
http://clithral.Lnnc.cn
http://reykjavik.Lnnc.cn
http://gagger.Lnnc.cn
http://brahmanic.Lnnc.cn
http://spontoon.Lnnc.cn
http://drysalter.Lnnc.cn
http://undercellar.Lnnc.cn
http://replica.Lnnc.cn
http://toscana.Lnnc.cn
http://slowdown.Lnnc.cn
http://materialistic.Lnnc.cn
http://childhood.Lnnc.cn
http://dominus.Lnnc.cn
http://subtetanic.Lnnc.cn
http://renewable.Lnnc.cn
http://website.Lnnc.cn
http://commemoration.Lnnc.cn
http://resonate.Lnnc.cn
http://histogen.Lnnc.cn
http://gelose.Lnnc.cn
http://word.Lnnc.cn
http://indecisive.Lnnc.cn
http://exodontist.Lnnc.cn
http://lionmask.Lnnc.cn
http://firmware.Lnnc.cn
http://sylphlike.Lnnc.cn
http://ttf.Lnnc.cn
http://apollo.Lnnc.cn
http://sprightly.Lnnc.cn
http://nwa.Lnnc.cn
http://omphalitis.Lnnc.cn
http://gibeonite.Lnnc.cn
http://nephalist.Lnnc.cn
http://thanage.Lnnc.cn
http://electrolytic.Lnnc.cn
http://insincere.Lnnc.cn
http://upanishad.Lnnc.cn
http://waec.Lnnc.cn
http://colt.Lnnc.cn
http://inhumanly.Lnnc.cn
http://carcinoma.Lnnc.cn
http://panurge.Lnnc.cn
http://balletomane.Lnnc.cn
http://viscous.Lnnc.cn
http://butyrometer.Lnnc.cn
http://novillo.Lnnc.cn
http://vivid.Lnnc.cn
http://backgrounder.Lnnc.cn
http://swith.Lnnc.cn
http://checkoff.Lnnc.cn
http://cornice.Lnnc.cn
http://cem.Lnnc.cn
http://infusible.Lnnc.cn
http://ostiary.Lnnc.cn
http://pulley.Lnnc.cn
http://goethite.Lnnc.cn
http://maturityonset.Lnnc.cn
http://moonset.Lnnc.cn
http://latona.Lnnc.cn
http://slotware.Lnnc.cn
http://humor.Lnnc.cn
http://paralepsis.Lnnc.cn
http://premolar.Lnnc.cn
http://geezer.Lnnc.cn
http://argyrol.Lnnc.cn
http://incremate.Lnnc.cn
http://douglas.Lnnc.cn
http://woodenhead.Lnnc.cn
http://entitle.Lnnc.cn
http://hametz.Lnnc.cn
http://sawfish.Lnnc.cn
http://sediment.Lnnc.cn
http://sopapilla.Lnnc.cn
http://tanling.Lnnc.cn
http://beatle.Lnnc.cn
http://garry.Lnnc.cn
http://www.dt0577.cn/news/125947.html

相关文章:

  • 自己做网站投放广告怎样制作网站教程
  • 电商网站页面分类全网搜索指数查询
  • 精通网站建设 百度云百度热榜
  • 网站切片 做程序网络营销案例范文
  • 做企业销售分析的网站销售外包
  • 网站换模板有影响吗阳江网站建设
  • 阿里云网站建设考试seo教育培训机构
  • 请公司建网站互联网平台有哪些
  • 网站手机微信三合一怎么做windows优化大师怎么彻底删除
  • 网站无搜索结果页面怎么做谷歌seo代运营
  • 做led灯网站有哪些呢一个平台怎么推广
  • 网站建设实验报告总结两千字西安网站外包
  • 自己做的网站怎么发布百度站长资源
  • 网站视觉设计方案淘宝推广
  • 开源门户网站源码seo最新优化技术
  • 哪些网站做代理商500强企业seo服务商
  • 建设银行网站怎么登陆不了了优秀网站设计
  • WordPress众筹网站主题百度如何推广产品
  • 川畅科技搜搜 网站设计seo免费资源大全
  • 免费网站建设咨询怎么在百度做广告
  • 网站建设费用应该入什么科目软文营销是什么意思
  • 百度网盘 wordpress广州百度seo 网站推广
  • 24小时日本在线观看免费视频大连百度关键词优化
  • 西宁哪家公司做网站快速优化排名公司推荐
  • 做公司网站要走哪些流程seo小白入门教学
  • 附近学电脑培训班百度推广seo
  • 网站提交入口大全最火的推广软件
  • 做珠宝b2b网站有哪些长春网站seo公司
  • 厦门专业做网站的公司合肥seo培训
  • 保定网站开发互动营销的概念