org.jplate.foundation.gof.command
Interface ContextCommandIfc<C>

Type Parameters:
C - The object that the command shall execute against.

public interface ContextCommandIfc<C>

A command that executes against a context (for instance the context may contain the state for execution). This is a version of the "Gang of Four" Command pattern: "Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations," p107 Design Patterns - Elements of Reusable Object-Oriented Software. This interface introduces a parameter that is used when executing the command entitled Context.

The following example illustrates a trivial implementation of a person and a context command for creating the person:

public final class Person
{
    private String _name;
    private int    _age;

    public Person ( final String name )
    {
        name = _name;
    }

    private Person ()
    {
    }

    public String getName () { return _name; }

    public int getAge () { return _age; }

    public void setAge ( final String age ) { _age = age; }
}

public final class CreatePersonContextCommand
    implements ContextCommandIfc <Person>
{
    public CreatePersonContextCommand ()
    {
    }

    public void execute ( final Person person )
    {
        //
        // Persistance work here to take
        // person and create that person...
        //
    }
}
    
As can be seen, using ContextCommandIfc allows a single command to be instantiated for execution on N contexts. For instance, above if all persistance work (like creating a database connection) is encapsulated in the execute method one command object is needed as state is maintained in Person.
Modifications:
    $Date: 2008-12-02 12:32:45 -0500 (Tue, 02 Dec 2008) $
    $Revision: 479 $
    $Author: sfloess $
    $HeadURL: https://jplate.svn.sourceforge.net/svnroot/jplate/trunk/src/dev/java/org/jplate/foundation/gof/command/ContextCommandIfc.java $
    


Method Summary
 void execute(C context)
          Executes the command against context.
 

Method Detail

execute

void execute(C context)
             throws ExecuteException
Executes the command against context.

Parameters:
context - The object against which self executes.
Throws:
ExcecuteException - If any problems arise executing the command.
ExecuteException