Interface CompensableCommand

All Superinterfaces:
Command, Serializable

public interface CompensableCommand extends Command
The CompensableCommand interface allows you to make a command reversible. When you make a command compensable, you associate a second command with it. The second command compensates for the effects of the first command by undoing its work as completely as possible.

The CompensableCommand interface defines one method, getCompensatingCommand(), which returns the compensating command associated with a command. The application programmer must implement both this method and the compensating command itself as part of implementing a compensable command.

A client that wants to reverse a compensable command calls the compensating command like this:

       myCommand.getCompensatingCommand().performExecute();
 

  • Method Details

    • getCompensatingCommand

      Command getCompensatingCommand() throws CommandException
      Retrieves the compensating command associated with the command. Call this method only after the associated compensable command has been run.

      The application programmer implements the getCompensatingCommand method as part of writing a compensable command. For a compensating command whose input properties are the output properties of the original command, the following implementation is sufficient:

            Command command = new MyCompensatingCommand();
            command.setInputPropertyX(outputPropertyP);
            return command;
       

      Returns:
      The compensating command associated with the command.
      Throws:
      CommandException - The superclass for all command exceptions. Specifically, UnavailableCompensatingCommandException is thrown if there is no compensating command associated with the command.