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

Type Parameters:
P - Command Parameter context-specific
R - Command Result context-specific
All Known Subinterfaces:
IParameterlessCommand
All Known Implementing Classes:
Command, ParameterlessCommand

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



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:09:51 PM $
Author:
Giovanni Azua
 

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

getResult

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

Returns:
Result of this ICommand execution.
Throws:
IllegalStateException - IReceiver was not set.
IllegalStateException - No result available.

setParameter

void setParameter(P aParameter)
                  throws IllegalArgumentException
Sets the parameter required for the execution of the target IReceiver.

Parameters:
aParameter - Parameter required for the execution of the target IReceiver.
Throws:
IllegalArgumentException - 'aParameter' must not be null.

setReceiver

void setReceiver(IReceiver<P,R> aReceiver)
                 throws IllegalArgumentException
Sets the IReceiver associated to this ICommand

Parameters:
aReceiver - to set
Throws:
IllegalArgumentException - 'aReceiver' must not be null.

execute

void execute()
             throws IllegalStateException
Executes the ICommand.

Throws:
IllegalStateException - IReceiver was not set.


Copyright © 2007-2009. All Rights Reserved.