I have a collection of objects using the command design pattern, ie they implement an abstract Command class and have an execute() method.
When called (for example) from the command line, you could do something like this, but its seriously clunky, how would you implement this:
public void main(String[] arg) {
Command c = null;
if(arg[0].equals("FirstCommand") {
c = new FirstCommand(arg[1]);
}
if(arg[0].equals("SecondCommand") {
c = new SecondCommand(arg[1], arg[2]);
}
if(arg[0].equals("ThirdCommand") {
c = new ThirdCommand(arg[1], Long.parseLong(arg[2]));
}
//.....etc....
c.execute();
}
Obviously as the list of available commands grows, this becomes quite tedious code