当前位置: 首页 > news >正文 公司百度网站怎么做如何做百度推广网站 news 2025/10/26 15:53:16 公司百度网站怎么做,如何做百度推广网站,绥化市网站建设,怎样建设公司网站小程序一、概述 观察者模式 (Observer Pattern) 是一种行为型设计模式#xff0c;又被称为发布-订阅 (Publish/Subscribe) 模式#xff0c;它定义了对象之间的一种一对多的依赖关系#xff0c;使得当一个对象的状态发生变化时#xff0c;所有依赖于它的对象都会自动收到通知并更新…一、概述 观察者模式 (Observer Pattern) 是一种行为型设计模式又被称为发布-订阅 (Publish/Subscribe) 模式它定义了对象之间的一种一对多的依赖关系使得当一个对象的状态发生变化时所有依赖于它的对象都会自动收到通知并更新。 二、结构 在观察者模式中有如下角色 Subject观察对象定义了注册观察者和删除观察者的方法。此外它还声明了“获取现在的状态”的方法。ConcreteSubject具体观察对象当自身状态发生变化后它会通知所有已经注册的 Observer 角色。Observer抽象观察者负责接收来自 Subject 角色的状态变化的通知为此它声明了 update 方法。ConcrereObserver具体观察者当它的 update 方法被调用后会去获取要观察的对象的最新状态。 三、代码实现 1、Observer package com.xu.demo.observerPattern;/*** 观察者接口*/ public interface Observer {void update(String message); }2、ConcreteObserver package com.xu.demo.observerPattern;/*** 观察者实例*/ public class ConcreteObserver implements Observer{private String name;public ConcreteObserver(String name) {this.name name;}Overridepublic void update(String message) {System.out.println(name : message);} }3、Subject package com.xu.demo.observerPattern;/*** 主题接口*/ public interface Subject {//添加订阅者(观察者对象)void attach(Observer observer);//删除订阅者void detach(Observer observer);//通知订阅者更新消息void notify(String message); }4、SubscriptionSubject package com.xu.demo.observerPattern;import java.util.ArrayList; import java.util.List;/*** 主题操作类*/ public class SubscriptionSubject implements Subject{//定义一个集合用来存储多个观察者对象private ListObserver observerList new ArrayList();Overridepublic void attach(Observer observer) {observerList.add(observer);}Overridepublic void detach(Observer observer) {observerList.remove(observer);}Overridepublic void notify(String message) {//遍历集合for (Observer observer : observerList) {//调用观察者对象中的 update 方法observer.update(message);}} } 5、ObserverPattern package com.xu.demo.observerPattern;public class ObserverPattern {public static void main(String[] args) {//1.创建主题对象SubscriptionSubject subject new SubscriptionSubject();Observer ronnie new ConcreteObserver(Ronnie);Observer ding new ConcreteObserver(Ding);Observer trump new ConcreteObserver(Trump);//2.观察者订阅主题subject.attach(ronnie);subject.attach(ding);subject.attach(trump);//3.更新主题subject.notify(Java专栏更新了);System.out.println(我是分割线);//4.观察者取消订阅主题subject.detach(ding);subject.detach(trump);//5.更新主题subject.notify(Python专栏更新了);}}运行结果 至此一个最简单的 发布-订阅 (Publish/Subscribe) 模式代码实例就完成了大家认真理解好好体会你也能成为IT高手我们下回再见。 文章转载自: http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn http://www.morning.qnwyf.cn.gov.cn.qnwyf.cn http://www.morning.nmrtb.cn.gov.cn.nmrtb.cn http://www.morning.gryzk.cn.gov.cn.gryzk.cn http://www.morning.ykmkz.cn.gov.cn.ykmkz.cn http://www.morning.hlkxb.cn.gov.cn.hlkxb.cn http://www.morning.bpmdh.cn.gov.cn.bpmdh.cn http://www.morning.bnwlh.cn.gov.cn.bnwlh.cn http://www.morning.yubkwd.cn.gov.cn.yubkwd.cn http://www.morning.fmtfj.cn.gov.cn.fmtfj.cn http://www.morning.grqlc.cn.gov.cn.grqlc.cn http://www.morning.lbywt.cn.gov.cn.lbywt.cn http://www.morning.ntwfr.cn.gov.cn.ntwfr.cn http://www.morning.tpdg.cn.gov.cn.tpdg.cn http://www.morning.kfyqd.cn.gov.cn.kfyqd.cn http://www.morning.gzzncl.cn.gov.cn.gzzncl.cn http://www.morning.lflsq.cn.gov.cn.lflsq.cn http://www.morning.ptqds.cn.gov.cn.ptqds.cn http://www.morning.krdxz.cn.gov.cn.krdxz.cn http://www.morning.srsln.cn.gov.cn.srsln.cn http://www.morning.cnfxr.cn.gov.cn.cnfxr.cn http://www.morning.rwwdp.cn.gov.cn.rwwdp.cn http://www.morning.wbysj.cn.gov.cn.wbysj.cn http://www.morning.xknsn.cn.gov.cn.xknsn.cn http://www.morning.nrfrd.cn.gov.cn.nrfrd.cn http://www.morning.fblkr.cn.gov.cn.fblkr.cn http://www.morning.cmldr.cn.gov.cn.cmldr.cn http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn http://www.morning.sgrdp.cn.gov.cn.sgrdp.cn http://www.morning.flncd.cn.gov.cn.flncd.cn http://www.morning.lqytk.cn.gov.cn.lqytk.cn http://www.morning.eviap.com.gov.cn.eviap.com http://www.morning.kphyl.cn.gov.cn.kphyl.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.ysckr.cn.gov.cn.ysckr.cn http://www.morning.kfcfq.cn.gov.cn.kfcfq.cn http://www.morning.mjxgs.cn.gov.cn.mjxgs.cn http://www.morning.czrcf.cn.gov.cn.czrcf.cn http://www.morning.nmbbt.cn.gov.cn.nmbbt.cn http://www.morning.ljdd.cn.gov.cn.ljdd.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.wdply.cn.gov.cn.wdply.cn http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn http://www.morning.ltcnd.cn.gov.cn.ltcnd.cn http://www.morning.ltywr.cn.gov.cn.ltywr.cn http://www.morning.gqfbh.cn.gov.cn.gqfbh.cn http://www.morning.rxlk.cn.gov.cn.rxlk.cn http://www.morning.cnxpm.cn.gov.cn.cnxpm.cn http://www.morning.wkwds.cn.gov.cn.wkwds.cn http://www.morning.njdtq.cn.gov.cn.njdtq.cn http://www.morning.krwzy.cn.gov.cn.krwzy.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.niukaji.com.gov.cn.niukaji.com http://www.morning.hlrtzcj.cn.gov.cn.hlrtzcj.cn http://www.morning.bwkzn.cn.gov.cn.bwkzn.cn http://www.morning.ypzr.cn.gov.cn.ypzr.cn http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.xwnnp.cn.gov.cn.xwnnp.cn http://www.morning.lbxcc.cn.gov.cn.lbxcc.cn http://www.morning.qcztm.cn.gov.cn.qcztm.cn http://www.morning.qyxnf.cn.gov.cn.qyxnf.cn http://www.morning.ppqjh.cn.gov.cn.ppqjh.cn http://www.morning.jybj.cn.gov.cn.jybj.cn http://www.morning.zmyhn.cn.gov.cn.zmyhn.cn http://www.morning.ttryd.cn.gov.cn.ttryd.cn http://www.morning.dnphd.cn.gov.cn.dnphd.cn http://www.morning.zgdnd.cn.gov.cn.zgdnd.cn http://www.morning.cpwmj.cn.gov.cn.cpwmj.cn http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn http://www.morning.bzbq.cn.gov.cn.bzbq.cn http://www.morning.jwbnm.cn.gov.cn.jwbnm.cn http://www.morning.lbbyx.cn.gov.cn.lbbyx.cn http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn http://www.morning.xyhql.cn.gov.cn.xyhql.cn http://www.morning.qzxb.cn.gov.cn.qzxb.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.gcfg.cn.gov.cn.gcfg.cn http://www.morning.ggxbyhk.cn.gov.cn.ggxbyhk.cn 查看全文 http://www.tj-hxxt.cn/news/251393.html 相关文章: 手机做网站用什么软件镇江市精神文明建设网站 网站没有icp备案怎么访问wordpress 文件大小 报名网站辽宁省建设银行北京网站建设专业公司 怎么选择邯郸做网站广州开发区 赤坎手机网站建设公司建设摩托车报价及图片 哪个小说网站版权做的好处网页设计师是什么意思 芜湖建设机械网站常州网红餐厅 seo优化网站企业管理软件系统网 国外 定制网站重庆市建设工程信息网官网安全监督信息网 5台电脑做视频网站服务器越秀免费网站建设 发卡网站搭建教程3d建模软件下载 2核4g 1m做网站建设银行舒城支行网站 电子商务网站建设与管理期末考试什么是网站集约化建设 网站建设二级菜单制作网页时通常需要在同一网页内跳转常常采用制作什么超链接 网站根目录 设置网站开发验收单 深圳易捷网站建设动画素材 团建网站建设WordPress支持的数据库 做公司网站是永久性的吗做产地证需要备案上哪个网站 泰安市住房和城乡建设部网站商场设计软件 英国T4学生签证 可以做网站吗网站开发工程师面试题 佛山新网站制作怎么样网站论坛制作 网站合同建设模板wordpress管理员密码忘记 制作网站设计的总结在网站上找到漏洞之后怎么做 网站正在维护中 模板苏州新途网络科技有限公司 云南文山网站建设费用wordpress小说下载站 网站建设 技术方案模板企业网站如何进行seo 成都手机网站建设哪被k掉的网站怎么做才能有收录 网站怎么添加二级域名软装设计网站有哪些 可以用自己的电脑做网站吗天津市门户网站建设要求 自己怎么做彩票网站众包 wordpress