import java.util.Observable; import java.util.Observer; /** * Abstract class to enable implicit invocation by extending Observable (since * that is not possible in interfaces). * * Implements Observable-related methods while staying independent storage * implementation. * * @author Alexander Schaap * * @param * Type of lines being stored */ public abstract class StorageObservable extends Observable implements StorageInterface { @Override public void add(T line) { addInternally(line); implicitlyInvoke(); } /** * Adds the line to the internal storage * * @param line * Line being stored */ protected abstract void addInternally(T line); /** * Shared implicit invocation implementation */ private void implicitlyInvoke() { setChanged(); implementationBasedNotify(); } /** * Observer notification dependent on implementation */ protected abstract void implementationBasedNotify(); @Override public void reset() { this.deleteObservers(); resetInternally(); } /** * Reset the storage dependent on implementation */ protected abstract void resetInternally(); public void connect(Observer o) { addObserver(o); } }