读书人

Java设计形式之观察者模式

发布时间: 2012-09-21 15:47:26 作者: rapoo

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();??
  • ??????????????
  • ????}??
  • } ?

  • 读书人网 >软件开发

    热点推荐