Encapsulate State for the Command Pattern with a Memento
The purpose of the Memento Pattern is to encapsulate state.
class Memento { private State state; public Memento(State stateToSave) { state = stateToSave; } public State useState() { return state; } }
When I use the Command Pattern, I combine it with the memento pattern.
Here is the interface that I use when implementing the command pattern.
/** * An Interface for a Command Object * see Command Pattern [GOF:233] * @author martin.spamer * @version 0.1 - 14:08:58 **/ public interface CommandInterface { /** * An Interface for a Command Object * see Command Pattern [GOF:233] * @param java.util.Properties * @return java.util.Properties */ public java.util.Properties execute( java.util.Properties properties) throws CommandException ; }