Implementing ProcessManager.add as an undoable operation.

JAVA PRIMER
JCommands: A Flexible Undo Framework for Java

Andreas Bäcker
Listing 2. Implementing ProcessManager.add as an undoable operation.


class AddProcessDesc extends Command {
	private ProcessDesc p;
	private ProcessManager pm;

	public AddProcessDesc(ProcessDesc p, ProcessManager pm) {
		super("Add Process"); // Used for external representation
		this.p  = p;
		this.pm = pm;
	}

	public void apply() { pm.add(p); }

	public void undo() { pm.remove(p); }
}

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.