intermediateObserver Pattern

Java's standard library included java.util.Observer and java.util.Observable since version 1.0 — why were they deprecated?

Both types were deprecated in Java 9 because their design had real, structural limitations that a hand-rolled implementation of the pattern avoids. Observable is a class, not an interface, so any class that wanted to be observable had to extend it — and since Java only allows single inheritance, that used up the one inheritance slot a class gets, blocking it from extending anything else. The API also offered no guarantees around notification order or thread-safety, and its setChanged()/notifyObservers() split made it easy to forget to mark state as changed before notifying. Modern Java code either hand-rolls the pattern with a custom interface, exactly as shown when building it from scratch, or uses the reactive java.util.concurrent.Flow API introduced in Java 9, which was designed with backpressure and proper interface-based composition in mind.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to How does a typical Spring Boot @Service class often act as a Facade, even without anyone naming it that way?← Back to all Low-Level Design & Design Patterns questions