Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  This is free and unencumbered software released into the public domain.
  Anyone is free to copy, modify, publish, use, compile, sell, or
  distribute this software, either in source code form or as a compiled
  binary, for any purpose, commercial or non-commercial, and by any
  In jurisdictions that recognize copyright laws, the author or authors
 of this software dedicate any and all copyright interest in the
 software to the public domain. We make this dedication for the benefit
 of the public at large and to the detriment of our heirs and
 successors. We intend this dedication to be an overt act of
 relinquishment in perpetuity of all present and future rights to this
 software under copyright law.
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