|
||||||||||
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 IInvoker<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 "Invoker".
//
// 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 | |
---|---|
R |
getResult()
Returns the result of the execution of the ICommand . |
void |
invoke()
Starts the appropriate ICommand . |
void |
setCommand(ICommand<P,R> aCommand)
Sets the ICommand to start as result of executing the
invoke method. |
void |
setParameter(P aParameter)
Sets the parameter required for the execution of the target ICommand . |
Method Detail |
---|
void setCommand(ICommand<P,R> aCommand)
ICommand
to start as result of executing the
invoke method.
aCommand
- ICommand
to set.R getResult() throws IllegalStateException
ICommand
.
ICommand
.
IllegalStateException
- 'ICommand was not set'
IllegalStateException
- 'No results available'void invoke() throws IllegalStateException
ICommand
.
IllegalStateException
- 'ICommand was not set'void setParameter(P aParameter)
ICommand
.
aParameter
- Parameter required for the execution of the target
ICommand
.
IllegalArgumentException
- Underlying implementations will
impose different preconditions on the aParameter argument
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |