Is there a preferred idiom for posting an “initial state” for new observers in the Observer pattern?
Most of the available materials and examples describing the Observer pattern suggest that observers are interested in notifying about changes, but do not care about the “initial state” (the current state when observers subscribe to changes).
One possibility would be to click on the “initial” (current) state on new observers when signing them, for example:
public class MyObservable extends java.util.Observable { public synchronized void addObserver(Observer observer) { super.addObserver(observer);
Is there a better / preferred approach?
source share