I have this interface:
public interface Command {
T execute(String... args);
}
it works fine for most uses. But when I try to mode
What if instead of having an interface like:
public interface Command {
T execute(String... args);
}
You instead had:
public interface Command {
void execute(String... args);
T getResult();
bool hasResult();
}
Then callers would do:
public void doSomething(Command> cmd) {
cmd.execute(args);
if(cmd.hasResult()) {
// ... do something with cmd.getResult() ...
}
}
You could also create an interface VoidCommmand that extends Command, if you like.
This seems like the cleanest solution to me.