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

网站建设公司有多少网站是什么时候出现的

网站建设公司有多少,网站是什么时候出现的,wordpress风格化页面,如何做网络营销推广的事项文章目录 1 概述2 实现3 总结 1 概述 观察者模式可以分为观察者和被观察者#xff0c;观察者通过注册到一个被观察者中#xff0c;也可视为订阅#xff0c;当被观察者的数据发生改变时#xff0c;会通知到观察者#xff0c;观察者可以据此做出反应。 可以类比订阅报纸观察者通过注册到一个被观察者中也可视为订阅当被观察者的数据发生改变时会通知到观察者观察者可以据此做出反应。 可以类比订阅报纸报社就是被观察者订阅者就是观察者订阅者通过订阅报纸与报社建立联系而报社有新报纸则主动投递给订阅者。 2 实现 这里以Head First 设计模式中的观察者模型为例。 讲的是一个气象监测站模型气象站有三个传感器分别采集温度、湿度和气压三个值。气象站采集完数据之后会将数据设置到WeatherData对象中而WeatherData数据更新后需要同时将数据更新到三个显示装置中。 这里就是使用了观察者模式WeatherData是数据中心是被观察者而显示装置则是观察者当观察者订阅之后数据中心的变化都会主动通知到观察者。 这个模型的类图如下 其中最重要的就是Subject和Observer接口这里Subject就是被观察者的总接口而Observer接口则是观察者总接口。Display接口则是因为多个显示器都拥有共同的Display行为。 WeatherData实现Subject成为一个具体的Subject而三个Display则实现Observer接口成为观察者实例。 下面是代码实例 Subject接口 public interface Subject {void registerObserver(Observer o);void removeObserver(Observer o);void notifyObservers(); }拥有对Observer对象操作的注册和删除操作也有通知各个Observer的方法。 Observer接口 public interface Observer {void update(float temperature, float humidity, float pressure); }观察者接口拥有Observer的公用操作Subject通过该接口来更新各个Observer中的数据。被观察者其实就是通过这个接口来通知到各个观察者的 DisplayElement接口 public interface DisplayElement {public void display(); }各个Display的公用方法 WeatherData类 public class WeatherData implements Subject {private ListObserver observers;private float temperature;private float humidity;private float pressure;public WeatherData() {observers new ArrayListObserver();}public void registerObserver(Observer o) {observers.add(o);}public void removeObserver(Observer o) {observers.remove(o);}public void notifyObservers() {for (Observer observer : observers) {observer.update(temperature, humidity, pressure);}}public void measurementsChanged() {notifyObservers();}public void setMeasurements(float temperature, float humidity, float pressure) {this.temperature temperature;this.humidity humidity;this.pressure pressure;measurementsChanged();}public float getTemperature() {return temperature;}public float getHumidity() {return humidity;}public float getPressure() {return pressure;}}具体的被观察者类会有一个存有所有观察者对象的集合当数据变化时会遍历这个集合来通知观察者而通知就是调用观察者的update方法。 ForecastDisplay类 public class ForecastDisplay implements Observer, DisplayElement {private float currentPressure 29.92f; private float lastPressure;private WeatherData weatherData;public ForecastDisplay(WeatherData weatherData) {this.weatherData weatherData;weatherData.registerObserver(this);}public void update(float temp, float humidity, float pressure) {lastPressure currentPressure;currentPressure pressure;display();}public void display() {System.out.print(Forecast: );if (currentPressure lastPressure) {System.out.println(Improving weather on the way!);} else if (currentPressure lastPressure) {System.out.println(More of the same);} else if (currentPressure lastPressure) {System.out.println(Watch out for cooler, rainy weather);}} }这是三个具体的观察者其中的一个实现了Observer接口并持有WeatherData对象在ForecastDisplay对象创建的时候会将自己加到WeatherData被观察者对象的集合中保存。当数据变化时WeatherData会从集合中遍历到这个对象并调用其update方法。 其他三个观察者类似。 测试代码 public class WeatherStation {public static void main(String[] args) {WeatherData weatherData new WeatherData();CurrentConditionsDisplay currentDisplay new CurrentConditionsDisplay(weatherData);StatisticsDisplay statisticsDisplay new StatisticsDisplay(weatherData);ForecastDisplay forecastDisplay new ForecastDisplay(weatherData);weatherData.setMeasurements(80, 65, 30.4f);weatherData.setMeasurements(82, 70, 29.2f);weatherData.setMeasurements(78, 90, 29.2f);weatherData.removeObserver(forecastDisplay);weatherData.setMeasurements(62, 90, 28.1f);} }三个观察者显示器获取到了同样的更新数据但是他们可以根据自身的显示逻辑来做出不同的显示结果 Current conditions: 80.0F degrees and 65.0% humidity Avg/Max/Min temperature 80.0/80.0/80.0 Forecast: Improving weather on the way! Current conditions: 82.0F degrees and 70.0% humidity Avg/Max/Min temperature 81.0/82.0/80.0 Forecast: Watch out for cooler, rainy weather Current conditions: 78.0F degrees and 90.0% humidity Avg/Max/Min temperature 80.0/82.0/78.0 Forecast: More of the same Current conditions: 62.0F degrees and 90.0% humidity Avg/Max/Min temperature 75.5/82.0/62.0Process finished with exit code 03 总结 观察者加被观察者组成观察者模式观察者继承Observer接口该接口提供一个通知观察者的方法观察者持有被观察者的引用在构造方法中调用被观察者的注册方法将自身注册为一个观察者被观察者拥有一个观察者集合用于存储所有注册的观察者的对象观察者可以自己调用注册和注销方法将自身添加到被观察者的列表中或从列表中移除被观察者要通知观察者时遍历观察者集合调用观察者接口中的方法通知观察者
http://www.hkea.cn/news/14413679/

相关文章:

  • wordpress分站点wordpress 前台
  • 上海建设学院网站做直播网站有市场吗
  • 前端和网站部署做网站的终身免费vps
  • 京东商城网站的搜索引擎营销做的案例分析九一人才网赣州招聘
  • 好大夫 网站开发在网站接入银联怎么做
  • 郑州网站建设推广优化沈阳定制网站制作
  • 网站做数据分析的意义培训网站开发需求说明书
  • 网站开发支付宝二维码支付wordpress view插件
  • 求个网站好人有好报百度贴吧网站制作 流程
  • 菏泽去哪了做网站wordpress 调用特定分类文章
  • h5游戏网站入口wordpress访问速度太慢
  • 统计局网站建设情况做影视网站什么cms好用
  • 旅游网站开发意义网站建设不要摸板
  • 乐清装修网站哪个好网页传奇游戏排行榜2014前十名
  • 做外贸主页网站用什么的空间好点wordpress添加媒体无反应
  • 外贸小网站建设建俄语网站哪个公司最好
  • 做浏览单的网站服务好的丹阳网站建设
  • 南通企业做网站做阿里巴巴网站店铺装修费用
  • 食品网站架构农药放行单在哪个网站做
  • 长春营销型网站设计备案域名指向一个网站
  • 徐州企业建站系统php网站开发实例教程 源码
  • 网站建设及维护干什么的傻瓜式网站源码
  • odoo 网站开发福建省网站备案注销
  • 五金表带厂东莞网站建设做网站横幅的软件
  • 怎么查看网站服务器位置杭州 app开发公司
  • 太白 网站建设设迹官网
  • 打鱼跟电子游戏网站怎么做免费网站大全推荐
  • 休闲零食网站建设+中企动力佛山网站建设科技有限公司
  • 快站app官网下载外贸网站源码免费
  • 建湖网站设计wap网站欣赏