Skip to content

Instantly share code, notes, and snippets.

@iamkirkbater
Created October 6, 2016 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamkirkbater/35fa12a48c736f0ae09a660a8d31c926 to your computer and use it in GitHub Desktop.
Save iamkirkbater/35fa12a48c736f0ae09a660a8d31c926 to your computer and use it in GitHub Desktop.
This is an example of the command pattern for the ISTE 422 Final Project at RIT.
public interface InputParser {
// variables
Database database;
// methods
void parseFile(File inputFile);
Database getDatabase();
}
public class XmlInputParser implements InputParser {
Database database;
public void parseFile(File inputFile) {
// parses the file into a database
}
public Database getDatabase() {
return this.database;
}
// this is where you would put the private methods to parse the individual xml file
}
public class EdgeInputParser implements InputParser {
Database database;
public void parseFile(File inputFile) {
// parses the file into a database
}
public Database getDatabase() {
return this.database;
}
// this is where you would put the private methods to parse the individual edge file
}
public class RunDDLCreator {
public static void main(string[] args)
{
InputParser parser;
File inputFile;
// this is where the
// code to get the input file
// would go, and then put it
// in the inputFile variable
switch (inputFile.fileType)
{
case "xml":
Parser = new XmlInputParser();
break;
case "edg":
Parser = new EdgeInputParser();
break;
default:
throw new UnexpectedFiletypeException();
break;
}
parser.parseFile();
// then essentially you would do something similar to get the
// DDL creator you need to use instantiated
ddlcreator.createDDL();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment