org.perfectjpattern.core.api.behavioral.command
Interface IInvoker<P,R>

Type Parameters:
P - Command Parameter context-specific
R - Command Result context-specific
All Known Subinterfaces:
IParameterlessInvoker
All Known Implementing Classes:
Invoker, ParameterlessInvoker

public 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".



Example usage:

    //
    // 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());
 

Version:
$Revision: 1.0 $ $Date: Jun 19, 2007 11:11:00 PM $
Author:
Giovanni Azua
 

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

setCommand

void setCommand(ICommand<P,R> aCommand)
Sets the ICommand to start as result of executing the invoke method.

Parameters:
aCommand - ICommand to set.

getResult

R getResult()
            throws IllegalStateException
Returns the result of the execution of the ICommand.

Returns:
Result of the execution of the ICommand.
Throws:
IllegalStateException - 'ICommand was not set'
IllegalStateException - 'No results available'

invoke

void invoke()
            throws IllegalStateException
Starts the appropriate ICommand.

Throws:
IllegalStateException - 'ICommand was not set'

setParameter

void setParameter(P aParameter)
Sets the parameter required for the execution of the target ICommand.

Parameters:
aParameter - Parameter required for the execution of the target ICommand.
Throws:
IllegalArgumentException - Underlying implementations will impose different preconditions on the aParameter argument


Copyright © 2007-2009. All Rights Reserved.