- 浏览: 728091 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (419)
- 杂软粉墨 (2)
- 创意灵感 (3)
- 经验记录 (137)
- 开源轨迹 (2)
- sip-communicator (2)
- 闲侃杂谈 (8)
- 问题交流 (24)
- 概念模式 (32)
- 难点备案 (5)
- JwChat (1)
- 中国象棋 (1)
- 教育探索 (6)
- 英语研究 (58)
- 星际争霸 (1)
- 电信知识 (1)
- 软件架构 (3)
- 哲学探索 (26)
- 算法灵魂 (8)
- 近视探索 (6)
- 数学数学 (3)
- 牛角钻尖 (23)
- 至强文言 (3)
- 数据结构 (1)
- 宇宙物理 (2)
- 网络架构 (3)
- 游戏领域 (4)
- 图形处理 (2)
- 修炼之路 (8)
- 读书天地 (20)
- 编解乱码 (2)
- 概念探索 (8)
- 格物致知 (1)
- 其它语言 (1)
- 测试领域 (3)
- 文化风流 (1)
- JQuery (1)
- 網頁領域 (1)
- Unix/Linux (1)
- Inside JVM (1)
- 异常分析 (1)
最新评论
-
suyujie:
引用
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
suyujie:
HTML <a> 标签灰显禁用 -
iamzhoug37:
您能说一下"局部变量不受文本顺序限制" 是 ...
声明前为什么能赋值却不能输出,都是使用
consistent communication model
for full article please refer to:
http://people.scs.carleton.ca/~ldnel/2404notes/330_patterns/GammaPatterns/Observer/
many dependent objects, and a subject which they are dependent on.
the trigger factor is the subject's state has changed
thus many registered(dependent) objects get notified by the subject
and then the registered observers(objects) quires the subject to synchronize its state with that of the subject's.
now i'm reading GOF design pattern observer part:
Mapping subjects to their observers. The simplest way for a subject to keep
track of the observers it should notify is to store references to them explicitly in
the subject. However, such storage may be too expensive when there are many
subjects and few observers. One solution is to trade space for time by using an
associative look-up (e.g., a hash table) to maintain the subject-to-observer
mapping. Thus a subject with no observers does not incur storage overhead. On
the other hand, this approach increases the cost of accessing the observers .
中文翻译:
subject是观察者模式中的主体,即被观察者
observer即观察者模式中的观察者
在一个系统中 可以有多个subject对应多个observer
他们之间是要保持关联关系的
这种关系就是哪些observer观察哪些subject
而这些关系的维护最简单的就是在subject中显式维护它的那些observer的引用
就表明了它(subject)是受哪些observer观察的
一旦发生情况,它只需要通知这些它维护的observers
然而这样的存储在某种情况下太过昂贵,哪种情况呢 就是 many subjects and few observers
即许多subjects,少许observers
一种解决方案就是通过使用关联查找比如hash table来用空间换时间
这样子来维护subject-to-observer的映射
因此没有observer的subject也就不会引起存储花销
但同时这种方法也增加了访问observer的花费
mine:
why on earth it doesn't incur storage overhead? originally, what does it do? how is it too expensive?
let's assume, originally if it directly stores references of observers in concrete subject, and in the case of many subjects few observers, more of those subjects may maintain a relationship. it thus causes much more space expense than introducing ChangeManger. if using ChangeManager(associative look-up), more space will be used(the ChangeManager class), but lots of time will be saved, this is so called trade space for time . and in the situation of no observer, even no chman should be maintained in subject, it then does not incur storage overhead. and it will increase the cost of accessing the observers by looking up value by key than directly accessing the value(observer reference).
Added on 2012.11.17
观察者模式三要素
观察者,被观察者,观察事件
像这里:
Button.addActionListener(new ActionListener().........);
button就是被观察者
actionlistener就是观察者
观察事件是Action
而事件一般是在被观察者对象范围内发生的,因此往往当事件发生时,事件传递模式是由被观察者告知观察者,而之前,他们两者为了确立围绕某某事件的观察关系,需要所谓的“注册”。
发表评论
-
java语言中classes分类
2012-10-22 13:09 1584local class的scope是local,所以在方法 ... -
URL definition
2012-08-14 08:29 7229http://reg.163.com/login.jsp?ty ... -
how to defend against serialization and reflection attack for eager singleton
2012-08-08 09:18 1225//为什么要定义构造方法 因为不定义它也会有默认构造方法,而 ... -
Finalizer Guardian Idiom
2012-05-30 11:55 1274Effective Java 2nd 中Item 7: A ... -
我對多態的理解
2012-05-24 09:03 1025多态(polymorphism)是以一种看待事物更细致的角度来 ... -
Bridge Pattern
2011-06-17 11:59 790Intent Decouple an abstracti ... -
Composite Pattern
2011-06-17 09:12 914http://userpages.umbc.edu/~ta ... -
Factory Method
2011-05-27 23:46 943how does the factory method pat ... -
Law of Demeter
2011-04-07 09:23 1015http://en.wikipedia.org/wiki/La ... -
Several thread-safe singleton collection
2011-02-24 10:19 9941. static inner class publi ... -
关于Arrays.sort()方法用到的设计模式
2011-02-18 09:12 2848/** * Src is the sour ... -
何时使用LSP
2011-01-24 09:12 977当使用subclass无法满足LSP(Liskov Subst ... -
Command模式图详解
2011-01-12 16:53 931上图是command模式结构图,各个符号重点应该理解,符 ... -
IOC inversion体现在什么地方
2011-01-12 16:02 1037http://martinfowler.com/bliki/I ... -
什么时候需要synchronized
2010-12-02 15:32 1136当需要在某个方法上加synchronized关 ... -
多任务同时执行完毕后方执行后续任务
2010-12-02 10:20 1180多线程同时启动,执行完毕后启动新任务 1.传统join ... -
Apache Struts2 Architecture
2010-07-21 22:38 909Struts is a flexible control la ... -
开闭原则
2010-03-15 13:58 927Closed for Modification; Op ... -
多态之RTTI
2010-01-21 16:58 1359所谓RTTI,是Runtime Type Informatio ... -
26 Hints for Agile Software Development
2009-11-23 16:14 95126 Hints for Agile Software Dev ...
相关推荐
设计模式之观察者模式ObserverPattern
我们说学习Java应该从Swing开始,那么学习Swing最重要的思想就是对于观察者模式的理解(Observer Pattern)。因为,该设计模式在Java Swing框架中贯穿了始终。对于C#的委托、代理概念所使用的Callback(回调模式--...
ObserverPattern.unitypackage是一个以unity为例写的观察者模式的应用举例。有需要的同学请下载!
matlab开发-Observerpattern。观察者模式示例
Swift µframework 实现观察者模式Observer pattern
定义对象间的一种一对多的依赖关系,以便当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并自动刷新。
这是关于C#中的观察者模式的教程文章。我们首先介绍作为GoF模式之一的经典观察者模式。观察者模式通过使用事件机制集成到C#中,这将在接下来讨论。然后,我们讨论与在C#中使用事件/事件处理程序相关的问题。
设计模式之观察者模式和静态工厂的结合实践
例题代码:李先生希望及时知道气象站的天气预报及旅行社的每日旅行信息。 李先生就是具体的一个观察者,而气象站及旅行社就成为了主题。
设计模式之观察者模式和静态工厂的结合实践
NULL 博文链接:https://justcoding.iteye.com/blog/1476165
观察者模式 New's Station Observer Pattern演示
从生活中的例子可以看出,只要对订阅号进行关注的客户端,如果订阅号有什么更新,就会直接推送给订阅了的用户。从中,我们就可以得出观察者模式的定义。 观察者模式定义了一种一对多的依赖关系,让多个观察者对象...
主要介绍了C#观察者模式(Observer Pattern),主要以一个实例的形式讲述了C#观察者模式的实现过程,详细讲述了接口的定义、通知及动作的实现方法,需要的朋友可以参考下
组合模式(Composite Pattern),又叫部分整体模式,是用于把一组相似的对象当作一个单一的对象。组合模式依据树形结构来组合对象,用来表示部分以及整体层次。这种类型的设计模式属于结构型模式,它创建了对象组的...
主要介绍了JavaScript编程设计模式之观察者模式(Observer Pattern),简单说明了观察者模式的概念、原理并结合实例形式详细给出了观察者模式的相关实现与使用技巧,需要的朋友可以参考下
在设计一组依赖的对象与它们所依赖的对象之间一致(同步)的交流模型时,观察者模式(Observer Pattern)很有用。它可以使依赖对象的状态与它们所依赖的对象的状态保持同步。这组依赖的对象指的是观察者(Observer)...
1、策略模式STRATEGY PATTERN ...16、观察者模式OBSERVER PATTERN 17、责任链模式 18、访问者模式VISITOR PATTERN 19、状态模式 20、原型模式 21、中介者模式 22、解释器模式 23、亨元模式 24、备忘录模式