Chinaunix首页 | 论坛 | 博客
  • 博客访问: 258392
  • 博文数量: 60
  • 博客积分: 1222
  • 博客等级: 少尉
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-16 17:28
个人简介

从学通信的博士到从事IT行业的工程师 从原华为项目经理,到现任职公司架构师

文章分类

全部博文(60)

文章存档

2013年(18)

2012年(42)

我的朋友

分类: C/C++

2012-12-23 20:35:22

Observer is also known as dependents or publish-subscribe. When the object changes its state, its dependents will be notified and updated automatically. The key objects in this design pattern are subject and observer. A subject can have any number of observers. All observers will be notified once the subject changes its state. The subject should have methods to attach and detach observers. The concrete observer maintains (maybe not) a reference to the subject which it is interested in.

The observer pattern lets you vary subjects and observers independently. Normally the observers don't know existence of each other. Who will trigger the notification? I prefer to the client because the service is clear here. Certainly the subject can also do it.

Observers can only subscribe some aspects of one subject. Change-manager is used to maintain  the mapping between the subjects and observers.

阅读(659) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~