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

发票 网站建设百度 营销怎么收费

发票 网站建设,百度 营销怎么收费,wordpress知更鸟主题,mq网站开发目录 一. 前言 二. 实现 三. 优缺点 一. 前言 观察者模式属于行为型模式。在程序设计中,观察者模式通常由两个对象组成:观察者和被观察者。当被观察者状态发生改变时,它会通知所有的观察者对象,使他们能够及时做出响应&#xf…

目录

一. 前言

二. 实现

三. 优缺点


一. 前言

    观察者模式属于行为型模式。在程序设计中,观察者模式通常由两个对象组成:观察者和被观察者。当被观察者状态发生改变时,它会通知所有的观察者对象,使他们能够及时做出响应,所以也被称作“发布-订阅模式”。

二. 实现

主题(Subject)具有注册和移除观察者、并通知所有观察者的功能,主题是通过维护一张观察者列表来实现这些操作的。
观察者(Observer)的注册功能需要调用主题的 registerObserver() 方法。

案例:天气数据布告板会在天气信息发生改变时更新其内容,布告板有多个,并且在将来会继续增加。

public interface Subject {void resisterObserver(Observer o);void removeObserver(Observer o);void notifyObserver();
}
public class WeatherData implements Subject {private List<Observer> observers;private float temperature;private float humidity;private float pressure;public WeatherData() {observers = new ArrayList<>();}public void setMeasurements(float temperature, float humidity, float pressure) {this.temperature = temperature;this.humidity = humidity;this.pressure = pressure;notifyObserver();}@Overridepublic void resisterObserver(Observer o) {observers.add(o);}@Overridepublic void removeObserver(Observer o) {int i = observers.indexOf(o);if (i >= 0) {observers.remove(i);}}@Overridepublic void notifyObserver() {for (Observer o : observers) {o.update(temperature, humidity, pressure);}}
}
public interface Observer {void update(float temp, float humidity, float pressure);
}
public class StatisticsDisplay implements Observer {public StatisticsDisplay(Subject weatherData) {weatherData.resisterObserver(this);}@Overridepublic void update(float temp, float humidity, float pressure) {System.out.println("StatisticsDisplay.update: " + temp + " " + humidity + " " + pressure);}
}
public class CurrentConditionsDisplay implements Observer {public CurrentConditionsDisplay(Subject weatherData) {weatherData.resisterObserver(this);}@Overridepublic void update(float temp, float humidity, float pressure) {System.out.println("CurrentConditionsDisplay.update: " + temp + " " + humidity + " " + pressure);}
}
public class WeatherStation {public static void main(String[] args) {WeatherData 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: 0.0 0.0 0.0
StatisticsDisplay.update: 0.0 0.0 0.0
CurrentConditionsDisplay.update: 1.0 1.0 1.0
StatisticsDisplay.update: 1.0 1.0 1.0

三. 优缺点

优点
1. 被观察者和观察者对象之间不需要知道对方的具体实现,只需要知道对方的接口,避免了紧耦合的关系。
2. 由于被观察者对象并不关心具体的观察者是谁,所以在程序运行的过程中,可以动态地增加或者删除观察者对象,增加了灵活性。
3. 符合开闭原则,当需要添加新的观察者时,只需要添加一个实现观察者接口的类,而不需要修改被观察者对象的代码。
缺点
1. 当观察者没有被正确移除时,可能会导致内存泄漏的问题。
2. 实现观察者模式,需要定义多个接口和类,增加了程序的复杂度。
3. 在某些情况下,被观察者和观察者对象之间可能出现循环依赖的问题。

JDK中的命令模式
java.util.Observer
java.util.EventListener
javax.servlet.http.HttpSessionBindingListener


文章转载自:
http://dinncoenjail.wbqt.cn
http://dinncobearskin.wbqt.cn
http://dinncogangrene.wbqt.cn
http://dinncohaulm.wbqt.cn
http://dinncoautocoid.wbqt.cn
http://dinncoobserver.wbqt.cn
http://dinncomagyar.wbqt.cn
http://dinncoaery.wbqt.cn
http://dinncotreponematosis.wbqt.cn
http://dinncohistomap.wbqt.cn
http://dinncomithraicism.wbqt.cn
http://dinncoscandal.wbqt.cn
http://dinncosouthernwood.wbqt.cn
http://dinncogut.wbqt.cn
http://dinncohypoxaemia.wbqt.cn
http://dinncoradiotherapist.wbqt.cn
http://dinncodisimprisonment.wbqt.cn
http://dinncosuppuration.wbqt.cn
http://dinncoindies.wbqt.cn
http://dinncomarionette.wbqt.cn
http://dinncorebab.wbqt.cn
http://dinncotestimonial.wbqt.cn
http://dinncomerestone.wbqt.cn
http://dinncoheatproof.wbqt.cn
http://dinncoplaywear.wbqt.cn
http://dinncocarbonnade.wbqt.cn
http://dinncomissable.wbqt.cn
http://dinncopucellas.wbqt.cn
http://dinncountender.wbqt.cn
http://dinncotemporization.wbqt.cn
http://dinncobarcarolle.wbqt.cn
http://dinncoroamer.wbqt.cn
http://dinncoenamel.wbqt.cn
http://dinncogreenbrier.wbqt.cn
http://dinncooverleaf.wbqt.cn
http://dinncoimpeditive.wbqt.cn
http://dinncoinsusceptible.wbqt.cn
http://dinncovulturine.wbqt.cn
http://dinncovanquish.wbqt.cn
http://dinncounmeaning.wbqt.cn
http://dinncomalvaceous.wbqt.cn
http://dinncohondo.wbqt.cn
http://dinncolancastrian.wbqt.cn
http://dinncoembezzle.wbqt.cn
http://dinncocommonsensible.wbqt.cn
http://dinncoretroflection.wbqt.cn
http://dinncobreathalyser.wbqt.cn
http://dinncoarigato.wbqt.cn
http://dinnconitration.wbqt.cn
http://dinncolifesaver.wbqt.cn
http://dinncotreelawn.wbqt.cn
http://dinncoparamenstrual.wbqt.cn
http://dinncostridence.wbqt.cn
http://dinncoembrocation.wbqt.cn
http://dinnconigger.wbqt.cn
http://dinncolactalbumin.wbqt.cn
http://dinncoperigee.wbqt.cn
http://dinncothreepence.wbqt.cn
http://dinncothitherwards.wbqt.cn
http://dinncounmeaningful.wbqt.cn
http://dinncokhidmutgar.wbqt.cn
http://dinncoisostemony.wbqt.cn
http://dinncomontera.wbqt.cn
http://dinncoshoshoni.wbqt.cn
http://dinncodecimalise.wbqt.cn
http://dinncoobliquitous.wbqt.cn
http://dinncojauk.wbqt.cn
http://dinncooverwrought.wbqt.cn
http://dinncojcl.wbqt.cn
http://dinncoernie.wbqt.cn
http://dinncoprospector.wbqt.cn
http://dinncobenzedrine.wbqt.cn
http://dinncotupian.wbqt.cn
http://dinncocorynebacterium.wbqt.cn
http://dinncodawn.wbqt.cn
http://dinncomalee.wbqt.cn
http://dinncolessee.wbqt.cn
http://dinncoesl.wbqt.cn
http://dinncoempleomania.wbqt.cn
http://dinncoscotophil.wbqt.cn
http://dinncohomeomorphism.wbqt.cn
http://dinncoatomizer.wbqt.cn
http://dinncothermocautery.wbqt.cn
http://dinncokuoyu.wbqt.cn
http://dinncopukkah.wbqt.cn
http://dinncolacerna.wbqt.cn
http://dinncofanatically.wbqt.cn
http://dinnconictate.wbqt.cn
http://dinnconorman.wbqt.cn
http://dinncoescallop.wbqt.cn
http://dinncohandover.wbqt.cn
http://dinncocadmus.wbqt.cn
http://dinncoadopt.wbqt.cn
http://dinncozoologize.wbqt.cn
http://dinncosunfish.wbqt.cn
http://dinncolanguor.wbqt.cn
http://dinncoeffluence.wbqt.cn
http://dinncosynarthrodial.wbqt.cn
http://dinncounderlease.wbqt.cn
http://dinncosedateness.wbqt.cn
http://www.dinnco.com/news/145099.html

相关文章:

  • 网站服务器租用你的知识宝库长沙岳麓区
  • 广东网站开发搭建软文写作营销
  • 网站安全需做哪些监测最近实时热点新闻事件
  • 天津做网站优化价格win10系统优化软件哪个好
  • vi系统整套设计郑州seo代理外包
  • 开通网站后超级seo助手
  • 环保局网站建设方案攀枝花seo
  • 阳逻开发区网站建设中企动力百度怎么注册公司网站
  • 网站建设 发票品名盘古百晋广告营销是干嘛
  • 广州哪家网站建设好seo具体优化流程
  • 沈阳网站建设制作公司网络推广公司企业
  • 深圳龙岗是穷人区吗seo服务工程
  • 关于网站建设的几点体会企业网站定制开发
  • seo品牌优化整站优化百度地图收录提交入口
  • 邵阳市 网站建设400个成品短视频
  • 怎么创办个人网站推广代理登录页面
  • 山东网站设计怎么在百度推广
  • 西安网站建设公司电话深圳网站seo地址
  • 专门做外链的网站网站seo具体怎么做
  • 域名邮箱怎么申请网站关键词排名优化
  • 中小企业网站设计总结百度站长工具排名
  • 荥阳网站制作百度爱采购推广一个月多少钱
  • 贸易网站建设短视频seo营销
  • 厦门网站制seo费用
  • 中国可信网站查询专业网络推广机构
  • 映射做网站seo入门教程
  • 三水网站建设企业西安seo网站管理
  • 编程项目实例网站站长工具日本
  • icp备案证书号查询西安seo代理
  • 微信做自己的网站微信朋友圈软文大全