Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 package base;
All business logic as much as is practical should conform to the java command design pattern. All code that results in a change to data must be implemented as a command. A Command describes an individual unit of work or transaction. Execution of a command is usually a result of a business event, ie A student enrolling in a subject.
public abstract class Command {

Execute the command. An optional variable number of parameters should be passed at object instantiation. before the Command.execute() method is called. Should it not be possible to complete the execution of the command for any reason, the command must throw an IOException. When an IOException is thrown, the data store should not have been altered in anyway. (ie SQL transactions are rolled back).

Throws: Thrown if and only if the command can not be completed.
	public void run() throws IOException {
		throw new IllegalArgumentException(getClass().getSimpleName() + " may not be instantiated with parameters");
	protected abstract void execute() throws IOException;
	public abstract String getJsonParameters();
	public String toJson() {
		return "{\"c\":\"" + getClass().getSimpleName() + "\",\"p\":{" + getJsonParameters() + "}}";
New to GrepCode? Check out our FAQ X