|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
E
- The type of result obtained by executing this command.@Participant(value="Command") public interface Command<E>
A command represents a possibly undoable
operation
on a given receiver.
The result of the execution is called the command value and
can be acquired using the getResult()
method after
execution. Commands should always be executed by a
CommandProcessor
to ensure proper undo functionality.
When executed, commands may spawn new commands to be executed
immediately, i.e. before other commands in the current
list of commands being executed
by the command processor
used. The execution
of spawned commands is thus depth-first.
Commands are not thread-safe, and generally cannot be
shared. Instead, they can be copied
for "reuse".
CommandProcessor
,
CommandProcessingResult
Method Summary | |
---|---|
Command<E> |
copy()
Creates a copy of this command, excluding internal state information required for execution and undo. |
List<Command<E>> |
execute()
Performs the execution of this command. |
E |
getResult()
Returns the result of the execution of this
command. |
boolean |
isUndoable()
Returns true if this command has been executed and is undoable, false if not. |
E |
undo()
Perform undo of this command, if possible. |
Method Detail |
---|
Command<E> copy()
copy
in interface Copyable<Command<E>>
List<Command<E>> execute() throws CommandException
After successful execution, the result of the
execution can be obtained via the getResult()
method.
processor
currently
executing this command. Can be null or empty.
CommandException
- If the execution fails.undo()
E getResult()
execution
of this
command.
Invoking this method before execution will cause an illegal
state exception to be thrown. If undone
,
this command must be re-executed before the result can be
fetched again.
boolean isUndoable()
If undoable, the effect of the execution
can be undone by invoking undo()
.
E undo() throws CommandException
If this method is invoked and this command is not
undoable
, an exception will
be thrown.
The result of invoking undo on a command that has
not been executed
is undefined.
CommandException
- If the undo fails.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |