观察者模式在Jdk应用
- 查看
@Deprecated(since="9") public class Observable { private boolean changed = false; private Vector<Observer> obs; // 集合 # 查看接口 @Deprecated(since="9") public interface Observer { /** * This method is called whenever the observed object is changed. An * application calls an {@code Observable} object's * {@code notifyObservers} method to have all the object's * observers notified of the change. * * @param o the observable object. * @param arg an argument passed to the {@code notifyObservers} * method. */ void update(Observable o, Object arg); }
-
alt + 7 查看方法
-
角色分析
Observable 的作用和地位等价于 我们前面讲过Subject Observable 是类,不是接口,类中已经实现了核心的方法 ,即管理Observer的方法 add.. delete .. notify... Observer 的作用和地位等价于我们前面讲过的 Observer, 有update Observable 和 Observer 的使用方法和前面讲过的一样,只是Observable 是类,通过继承来实现观察者模式
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?