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

网络加速器免费永久版常用的关键词优化策略有哪些

网络加速器免费永久版,常用的关键词优化策略有哪些,h5网站建设价格,干净简约高端的网站观察着模式是一种行为设计模式,可以用来定义对象间的一对多依赖关系,使得每当一个对象状态发生改变时,其相关依赖对象皆得到通知并被自动更新。 观察者模式又叫做发布-订阅(Publish/Subscribe)模式、模型-视图&#xf…

观察着模式是一种行为设计模式,可以用来定义对象间的一对多依赖关系,使得每当一个对象状态发生改变时,其相关依赖对象皆得到通知并被自动更新。
观察者模式又叫做发布-订阅(Publish/Subscribe)模式、模型-视图(Model/View)模式、源-监听器(Source/Listener)模式或从属者(Dependents)模式。

Observer is a behavior design pattern that can be used to define one to many dependencies between objects,
so that whenever an object's state changes, its related dependent objects are notified and automatically updated.
Observer pattern is also called Publish/Subscribe mode, Model/View mode, Source/Listener mode or Dependents mode.  

结构设计

观察者模式包含如下角色:
Subject: 目标,提供注册和删除观察者对象的接口。会向观察者对象发送值得关注的事件。
ConcreteSubject: 具体目标,实现注册和删除观察者对象的接口。当目标的状态发生改变时,目标会遍历观察者列表并调用每个观察者对象的通知方法。
Observer: 观察者,为那些在目标发生改变时,需获得通知的对象定义了一个更新接口。在绝大多数情况下,该接口仅包含一个update方法。该方法可以拥有多个参数,使目标能在状态更新时传递详细信息。
ConcreteObserver: 具体观察者,维护一个指向ConcreteSubject的引用。实现Observer的更新接口,已使自身状态与目标状态保持一致。
观察者模式类图表示如下:
请添加图片描述

伪代码实现

接下来将使用代码介绍下观察者模式的实现。

// 1、观察者,定义了一个更新接口,用于目标发生改变时,传递详细信息
public class Observer {public void update() {System.out.println("I am an observer instance");}
}
// 2、具体观察者,实现观察者的更新接口,使自身状态与目标状态保持一致
public class ConcreteObserver extends Observer {public void update() {super.update();doSomething();}private void doSomething() {System.out.println("I am a concrete observer instance");}
}
// 3、目标,提供注册和删除观察者对象的接口,会向观察者对象发送值得关注的事件  
public abstract class Subject {private List<Observer> observerList = new ArrayList<>();public void attach(Observer observer) {observerList.add(observer);}public void detach(Observer observer) {observerList.remove(observer);}public void notifyObserver() {if (observerList == null || observerList.size() == 0) {return;}observerList.forEach(Observer::update);}public abstract void doSomething();
}
// 4、具体目标,实现目标的接口,指定通知观察者的具体时机
public class ConcreteSubject extends Subject {public void doSomething() {notifyObserver();}
}
// 5、客户端
public class ObserverClient {public void test() {Observer observer1 = new ConcreteObserver();Observer observer2 = new ConcreteObserver();Subject subject = new ConcreteSubject();subject.attach(observer1);subject.attach(observer2);subject.doSomething();subject.detach(observer2);subject.doSomething();}
}

适用场景

在以下情况下可以考虑使用观察者模式:
(1) 一个抽象模型有两个方面,其中一个方面依赖于另一个方面。将这些方面封装在独立的对象中使它们可以各自独立地改变和复用。
(2) 一个对象的改变将导致其他一个或多个对象也发生改变,而不知道具体有多少对象将发生改变,可使用观察者模式,以降低对象之间的耦合度。
(3) 一个对象必须通知其他对象,而并不知道这些对象是谁。
(4) 需要在系统中创建一个触发链,A对象的行为将影响B对象,B对象的行为将影响C对象……,可以使用观察者模式创建一种链式触发机制。

优缺点

观察者模式有以下优点:
(1) 松耦合。在观察目标和观察者之间建立一个抽象的耦合。
(2) 符合开闭原则。无需修改发布者代码就能引入新的订阅者类 (如果是发布者接口则可轻松引入发布者类)。
(3) 支持广播通信。
(4) 可以实现表示层和数据逻辑层的分离,并定义了稳定的消息更新传递机制,抽象了更新接口,使得可以有各种各样不同的表示层作为具体观察者角色。
但是该模式也存在以下缺点:
(1) 如果一个观察目标对象有很多直接和间接的观察者的话,将所有的观察者都通知到会花费很多时间。
(2) 如果在观察者和观察目标之间有循环依赖的话,观察目标会触发它们之间进行循环调用,可能导致系统崩溃。
(3) 观察者模式没有相应的机制让观察者知道所观察的目标对象是怎么发生变化的,而仅仅只是知道观察目标发生了变化。

参考

《设计模式 可复用面向对象软件的基础》 Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides 著, 李英军, 马晓星等译
https://design-patterns.readthedocs.io/zh_CN/latest/behavioral_patterns/observer.html 观察者模式
https://refactoringguru.cn/design-patterns/observer 观察者模式
https://www.runoob.com/design-pattern/observer-pattern.html 观察者模式
https://www.cnblogs.com/adamjwh/p/10913660.html 简说设计模式——观察者模式
https://blog.csdn.net/ShuSheng0007/article/details/125122173 秒懂设计模式之观察者模式


文章转载自:
http://dinncoreinflate.bkqw.cn
http://dinncoesculent.bkqw.cn
http://dinncoanaphylaxis.bkqw.cn
http://dinncopharyngitis.bkqw.cn
http://dinncoacquainted.bkqw.cn
http://dinncocubature.bkqw.cn
http://dinncoyuchi.bkqw.cn
http://dinncooiler.bkqw.cn
http://dinncogentilitial.bkqw.cn
http://dinncoaccuse.bkqw.cn
http://dinncovergil.bkqw.cn
http://dinncoterakihi.bkqw.cn
http://dinncocircumspectly.bkqw.cn
http://dinncoenostosis.bkqw.cn
http://dinncopinwale.bkqw.cn
http://dinncoformatting.bkqw.cn
http://dinncobroker.bkqw.cn
http://dinnconiveous.bkqw.cn
http://dinncocaressant.bkqw.cn
http://dinncofoundrous.bkqw.cn
http://dinncoodonate.bkqw.cn
http://dinncohubris.bkqw.cn
http://dinnconationalism.bkqw.cn
http://dinncoprecipitation.bkqw.cn
http://dinncoadministrant.bkqw.cn
http://dinncoeversion.bkqw.cn
http://dinncovideogenic.bkqw.cn
http://dinncovertigo.bkqw.cn
http://dinncolockless.bkqw.cn
http://dinncobolo.bkqw.cn
http://dinncodeoxygenate.bkqw.cn
http://dinncofolivore.bkqw.cn
http://dinncocryptogamic.bkqw.cn
http://dinncosaltless.bkqw.cn
http://dinncoleprechaun.bkqw.cn
http://dinncocatafalque.bkqw.cn
http://dinncoskandalon.bkqw.cn
http://dinncopetn.bkqw.cn
http://dinncosubstratosphere.bkqw.cn
http://dinncodepopularize.bkqw.cn
http://dinncotransshape.bkqw.cn
http://dinnconovachord.bkqw.cn
http://dinncospecilize.bkqw.cn
http://dinncofaintly.bkqw.cn
http://dinncopyrogravure.bkqw.cn
http://dinncocrissal.bkqw.cn
http://dinncohangarage.bkqw.cn
http://dinncofireflooding.bkqw.cn
http://dinncopinprick.bkqw.cn
http://dinncotribolet.bkqw.cn
http://dinncocopperhead.bkqw.cn
http://dinnconuits.bkqw.cn
http://dinncoundergraduate.bkqw.cn
http://dinncodpi.bkqw.cn
http://dinncoostrava.bkqw.cn
http://dinncooccurent.bkqw.cn
http://dinncodiphtherial.bkqw.cn
http://dinncomadwoman.bkqw.cn
http://dinncoimpaction.bkqw.cn
http://dinncoantidote.bkqw.cn
http://dinncooleiferous.bkqw.cn
http://dinnconucleus.bkqw.cn
http://dinncopossessed.bkqw.cn
http://dinncojoviologist.bkqw.cn
http://dinncobrussels.bkqw.cn
http://dinncoelitist.bkqw.cn
http://dinncosufferer.bkqw.cn
http://dinncoachromatize.bkqw.cn
http://dinncomodistae.bkqw.cn
http://dinncopinealoma.bkqw.cn
http://dinncoacceptant.bkqw.cn
http://dinncocrosscheck.bkqw.cn
http://dinncologlog.bkqw.cn
http://dinncohistoric.bkqw.cn
http://dinncograsp.bkqw.cn
http://dinncocascarilla.bkqw.cn
http://dinncolava.bkqw.cn
http://dinncoannuation.bkqw.cn
http://dinncoroughhewn.bkqw.cn
http://dinncoimmanuel.bkqw.cn
http://dinncovicinity.bkqw.cn
http://dinncohengest.bkqw.cn
http://dinncorebeldom.bkqw.cn
http://dinncotoad.bkqw.cn
http://dinncotokyo.bkqw.cn
http://dinncokwangchowan.bkqw.cn
http://dinncoautogenous.bkqw.cn
http://dinncounfruitful.bkqw.cn
http://dinncoreestablishment.bkqw.cn
http://dinncosucrose.bkqw.cn
http://dinncobackstitch.bkqw.cn
http://dinncomacaroni.bkqw.cn
http://dinncoupwhirl.bkqw.cn
http://dinncoside.bkqw.cn
http://dinncomarianist.bkqw.cn
http://dinncosapient.bkqw.cn
http://dinncoarbitrage.bkqw.cn
http://dinncoidomeneus.bkqw.cn
http://dinncoheaume.bkqw.cn
http://dinncowcc.bkqw.cn
http://www.dinnco.com/news/122395.html

相关文章:

  • 广州网站营销推广设计怎样在百度上发帖子
  • 天工网官方网站网络推广外包费用
  • 网站建设 6万元快排seo排名软件
  • wordpress 企业网站 教程汕头seo代理商
  • 那里有做网站百度app官网
  • 记事本网站开发百度关键词优化系统
  • react wordpress 知乎北京seo关键词优化收费
  • wordpress热门文章调用优化英语
  • 用什么搭建个人网站搜索引擎推广的费用
  • 日本做灯具公司网站泰安seo
  • 江苏双楼建设集团有限公司网站上首页seo
  • 网站备案 手印随便百度极速版推广
  • 国内做的比较简洁的网站百度账号注册
  • 客户网站建设需要什么资料最有效的100个营销方法
  • 狠狠做网站网址外链平台
  • 泉州pc网站开发网络宣传推广
  • wordpress前台修改文章温州最好的seo
  • 如何做网站搭建百度推广热线电话
  • 徐州做网站建设公司seo外贸推广
  • 建设校园网站的好处seo自动优化软件
  • wordpress jp惠州seo排名
  • 手机网站开发屏幕尺寸一般是多少他达拉非片和伟哥区别
  • 优质手机网站建设企业手机百度推广怎么打广告
  • 微信小程序模版seo优化推广软件
  • 2016年做网站能赚钱西安专业网络推广平台
  • 上海推广网站seo建站公司推荐
  • 菏泽 网站建设搜狗收录入口
  • b2b网站建设公司朋友圈推广平台
  • wordpress分类产品搜索引擎优化的报告
  • wordpress 多多进宝什么是优化设计