最新消息:

The Observer Pattern

读书学习 hamo 1113浏览 0评论

Observer – defines a ont-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

OO Principles

  • Strive for loosely coupled designs between objects that interact.

Bullet Points

  • The Observer Pattern defines a ont-to-many relationship between objects.
  • Subjects, or we also known them, Observables, update Observers using a common interface.
  • Observers are loosely coupled in that the observalbe knows nothing about them, other than that they implement the Observer interface.
  • You can push or pull the data of the Observalbe when using the pattern(pull is considered more “correct”).
  • Don’t depend on a specific order of notification for you Observers.
  • Java has several implementations of the Observer Pattern, including the gerneral purpose jave.util.Observable.
  • Watch out for issues with the java.util.Observable implementation.
  • Don’t be afraid to create our own Observable implementation if needed.
  • Swing makes heavy use of the Observer Pattern, as do many GUI frameworks.
  • You’ll also find the pattern in many other places, incluing JavaBeans and RMI.

转载请注明:哈默博客 » The Observer Pattern

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址