Purpose: Practice on using fake objects for sensing.
Goal: Implement a transactional command batchrunner that ensures that a series of commands either all runs successfully, or the whole chain is rolled back.
Interface
public class TransactionalCommandRunner {
public void addCommand(ICommand c);
public void execute();
}
public interface ICommand {
public void execute();
public void undo();
}
- Start simple:
- TransactionalCommandRunner can execute zero commands.
- TransactionalCommandRunner can execute one command.
- TransactionalCommandRunner can execute many commands.
- Implement rollback
- If the first command fails (throws an Exception), the rest of the commands are not executed.
- If the first command fails, it is not rolled back (undone).
- If the second command fails, the first command is rolled back.
- If a subsequent command fails, all preceding commands are rolled back.
- The exception thrown by the failing command is rethrown from TransactionalCommandRunner.execute().
No comments:
Post a Comment