Is java.util.Observable used anywhere?

前端 未结 2 1775
轮回少年
轮回少年 2020-12-24 06:36

Was chatting to a colleague about the design of Javas libraries. I mentioned I\'d always found it funny that the AWT/Swing classes called that essentially provide an Observa

相关标签:
2条回答
  • 2020-12-24 06:38

    Observer and Observable are still used in a lot of Eclipse wizard code for detecting when the stuff in input boxes changes, so the wizard itself can be updated. I've had to work with some of this stuff, changing it for our own needs.. :)

    0 讨论(0)
  • 2020-12-24 06:54

    They are not used, because their design is flawed: they are not type safe. You can attach any object that implements Observer to any Observable, which can result in subtle bugs down the line.

    Wrapping them inside a type safe interface is about the same amount of work as implementing the pattern from scratch, so I guess the latter is preferred in most cases.

    This is one of the things which are flawed in Java 1.0 due to suboptimal design choices made under time pressure (others include the Java 1.0 Collection API and java.util.Date), but due to the nature of public APIs can never anymore be removed (only deprecated).

    0 讨论(0)
提交回复
热议问题