好久之前看过Observer,但是,当时不是很清楚,应该是Java刚刚入门的原因....现在看来啊,是比较优秀、很好的设计模式!
Like the other forms of callback, this contains a hook point where you can change code. The difference is in the observer’s completely dynamic nature. It is often used for the specific case of changes based on other object’s change of state, but is also the basis of event management. Anytime you want to decouple the source of the call from the called code in a completely dynamic way.
Observer模式定义对象间的一对多的依赖关系,当一个对象的状态发生改变时, 所有依赖于它的对象都得到通知并被自动更新。JDK中内置的observer设计模式的实现由java.util.Observable类和 java.util.Observer接口组成。
具体的实例讲解,参考这个案例 或者 是教材中的案例都是不错的选择!
观察者模式详解
本文介绍了观察者模式的基本概念及其在Java中的应用。该模式通过定义对象间的一对多依赖关系来实现当一个对象状态发生变化时,所有依赖于它的对象都能得到通知并自动更新。文章还提到了JDK内置的实现方式,并推荐了具体实例供读者参考。
440

被折叠的 条评论
为什么被折叠?



