首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

Java设计形式之观察者模式

2012-09-21 
Java设计模式之观察者模式OBSERVER?(Object Behavioral)?Purpose?Lets one or more objects be notified o

Java设计模式之观察者模式

OBSERVER?(Object Behavioral)?
Purpose?
Lets one or more objects be notified of state changes in other?
objects within the system.?
Use When?
1 State changes in one or more objects should trigger behavior?
? in other objects?
2 Broadcasting capabilities are required.?
3 An understanding exists that objects will be blind to the?
? expense of notification.?
Example?
This pattern can be found in almost every GUI environment.?
When buttons, text, and other fields are placed in applications?
the application typically registers as a listener for those controls.?
When a user triggers an event, such as clicking a button, the?
control iterates through its registered observers and sends a?
notification to each.?
new?ConcreteObserver();??

  • ????????subject.attach(observer1);??
  • ????????subject.attach(observer2);??
  • ????????subject.attach(observer3);??
  • ????????subject.notifyObserver();??
  • ??????????????
  • ????}??
  • } ?

  • 热点排行