I’m using callables quite often , and I’ve stubled upon a question that irritates me:
Lets say that to run function foo() , one needs to do a couple of checks first.
Should you 1. Insert the checks as part of the Callable :
class A implements Callable<Long> { ... public Long call() { check1(); check2(); return (run()); }
- OR , insert all this logic into another class (ALogic) and use the Callable a mere shell for the executor?
class A implements Callable {
...
public Long call() {
ALogic aLogic = new ALogic();
return (aLogic.run());
}
What do you think are the pro’s and con’s? What do you usually prefer?
My general advice when implementing callback [Java keyword] interfaces is concentrate on making the [non-Java keyword] interface appropriate for the called type. There generally shouldn’t be that much in the anonymous inner class (or whatever), but more than just forwarding call.
Also, it’s generally not good to have an object that is constructed and then only has a single method called on it. Make it a static method (which may, perhaps, in turn create an object through a private constructor and run that).