|
||||||||||
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 IReceiver<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 "Receiver".
//
// 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()
Starts the execution of the IReceiver . |
R |
getResult()
Returns result out of executing this IReceiver . |
void |
setParameter(P aParameter)
Sets the input parameter required for the execution of this IReceiver . |
Method Detail |
---|
void setParameter(P aParameter) throws IllegalArgumentException
IReceiver
.
aParameter
- Parameter required for executing the
IReceiver
.
IllegalArgumentException
- 'aParameter' must not be null.R getResult() throws IllegalStateException
IReceiver
.
IReceiver
.
IllegalStateException
- No result available.void execute() throws IllegalStateException
IReceiver
.
IllegalStateException
- Parameter not set.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |