
Command

Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. Builds an undo/redo manager and a set of command classes.
Source Code
/** * Declares an interface for executing an operation * @role __Command */ public interface Command { /** this method is called by client to execute this command */ void executeCommand();} /** * Defines a binding betweeen a Receiver object and an action. * Implements Command by invoking the corresponding operation(s) on Receiver */ public class CommandA implements Command { public CommandA() { // put command initialization code here } /** @see patterns.gof.command.Command#executeCommand()*/ public void executeCommand() { // provide implementation here } } /** * Defines a binding betweeen a Receiver object and an action. * Implements Command by invoking the corresponding operation(s) on Receiver */ public class CommandB implements Command { public CommandB() { // put command initialization code here } /** @see patterns.gof.command.Command#executeCommand()*/ public void executeCommand() { // provide implementation here } } /** * Concrete Command that executes a sequence of Commands. */ public class MacroCommand implements Command { /** Commands to execute */ private Command[] commands; /** @param commands Commands to execute */ public MacroCommand(Command[] commands) { this.commands = commands; } /** Executes sequence of Commands */ public void executeCommand() { if (commands != null) { for (int i = 0; i < commands.length; i++) { commands[i].executeCommand(); } } } }