面向对象系统分析与设计_观察者模式.ppt_第1页
面向对象系统分析与设计_观察者模式.ppt_第2页
面向对象系统分析与设计_观察者模式.ppt_第3页
面向对象系统分析与设计_观察者模式.ppt_第4页
面向对象系统分析与设计_观察者模式.ppt_第5页
已阅读5页,还剩11页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,1,OO System Analysis /取得温度 float humidity = getHumidity(); /取得湿度 float pressure = getPressure(); /取得气压 currentConditionsDisplay.update(temp, humidity, pressure); /同步显示当前天气状况 statisticsDisplay.update(temp, humidity, pressure

2、); /同步显示天气统计信息 forecastDisplay.update(temp, humidity, pressure); /同步显示天气预报信息 ,2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,6,2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,7,Our job is:,To create an app that uses the WheatherData object t

3、o update three displays.,2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,8,The kernel of the problem,WeatherData object,to update if you require,displays,publishers,subscribers,to deliver if you subscribe,subject object,observer objects,to notify if you observe,2020年10月3

4、1日星期六,Neusoft Computer Science and Technology Department copy right,9,The Observer Pattern,The Observer Pattern defines a one-to-many relationship between objects so that when one object changes state, all of its dependents are notified and updated automatically.,2020年10月31日星期六,Neusoft Computer Scie

5、nce and Technology Department copy right,10,Class diagram for Observer Pattern,Each subject can have many observers,update() will be called when the Subjects state changes.,These methods will be called When to register as observers , remove themselves from Being observers, or update all the observer

6、s whenever state changes.,2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,11,To develop app from the interface,Subject(被观察的对象接口) 规定ConcreteSubject的统一接口; 每个Subject可以有多个Observer; ConcreteSubject(具体被观察对象) 维护对所有具体观察者的引用的列表; 状态发生变化时会发送通知给所有注册的观察者。 Observer(观察者接口) 规定ConcreteOb

7、server的统一接口; 定义了一个update()方法,在被观察对象状态改变时会被调用。 ConcreteObserver(具体观察者) 维护一个对ConcreteSubject的引用; 特定状态与ConcreteSubject同步; 实现Observer接口,通过update()方法接收ConcreteSubject的通知。,2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,12,顺序图,2020年10月31日星期六,Neusoft Computer Science and Techno

8、logy Department copy right,13,2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,14,Designing the Weather Station,Exercise: A Spring Tour plan,Spring tour plan manage system need to maintain a collection of the participants Notify all members of the information about the plan Each member have their own arrival at the point of collection,2020年10月31日星期六,Neusoft Computer Science and Technology Department copy right,15,2020年10月31日星期六,Neusoft Computer

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论