import java.util.HashSet; import java.util.Iterator; import java.util.Set; public abstract class ObservableObject implements Observable { private Set observers = new HashSet(); @Override public void add(Observer o) { observers.add(o); o.update(); // as to display current value } @Override public void notifyAllObservers() { Iterator iter = observers.iterator(); while (iter.hasNext()) { Observer o = iter.next(); o.update(); } /* Koden over tilsvarer en vanlig for-loekke Skrevet paa denne maaten for aa illustrere bruk av iterator for (Observer o : observers) { o.update(); } */ } }