4,Simplified version of class Notification.

JAVA PRIMER
JCommands: A Flexible Undo Framework for Java

Andreas Bäcker
Listing 4. Simplified version of class Notification.


public class Notification extends Command {
	// The object that notifies its observers
	private java.util.Observable observable;
	// Messages being sent to observers
	private Object applyArg, undoArg, redoArg;

	public Notification(java.util.Observable o, int applyID, int undoID, Object ob) {
		this.observable = o;
		this.applyArg = new CmdArg1(applyID, ob);
		this.undoArg = new CmdArg1(undoID, ob)
		this.redoArg = this.applyArg;
	}

	public void apply() {
		observable.notifyObservers(applyArg);
	}

	public void undo() {
		observable.notifyObservers(undoArg);
	}
}