|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
P
- Command Parameter context-specificR
- Command Result context-specificpublic interface ICommand<P,R>
Command Design Pattern: Encapsulate a request as an object,
thereby letting you parameterize clients with different
requests, queue or log requests, and support undoable operations.
(Gamma et al, Design Patterns)
Responsibility: Abstract generic definition of the "Command".
//
// Create Command Pattern elements
//
IInvoker myInvoker = new ConcreteInvoker();
ICommand myCommand = new ConcreteCommand();
IReceiver myReceiver = new ConcreteReceiver();
//
// Associate Command Pattern elements
//
myInvoker.setCommand(myCommand);
myCommand.setReceiver(myReceiver);
//
// Optionally parameterize the Invoker
//
myInvoker.setParameter(new SomeParameter());
//
// Execute Invoker's invoke method that triggers execution of
// Command and Receiver
//
myInvoker.invoke();
//
// Optionally and if the Command is synchronous, retrieve a result
//
System.out.println(myInvoker.getResult().toString());
Method Summary | |
---|---|
void |
execute()
Executes the ICommand . |
R |
getResult()
Returns the result of this ICommand execution. |
void |
setParameter(P aParameter)
Sets the parameter required for the execution of the target IReceiver . |
void |
setReceiver(IReceiver<P,R> aReceiver)
Sets the IReceiver associated to this ICommand |
Method Detail |
---|
R getResult() throws IllegalStateException
ICommand
execution.
ICommand
execution.
IllegalStateException
- IReceiver was not set.
IllegalStateException
- No result available.void setParameter(P aParameter) throws IllegalArgumentException
IReceiver
.
aParameter
- Parameter required for the execution of the target
IReceiver
.
IllegalArgumentException
- 'aParameter' must not be null.void setReceiver(IReceiver<P,R> aReceiver) throws IllegalArgumentException
IReceiver
associated to this ICommand
aReceiver
- to set
IllegalArgumentException
- 'aReceiver' must not be null.void execute() throws IllegalStateException
ICommand
.
IllegalStateException
- IReceiver was not set.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |