Is it considered bad design to have a 'facade method' (I can't think of a better term). Example:
public class MyService() {
public void doThis() {
// do something
}
public int doThat() {
// do something
}
public boolean isThisTrue(String str) {
// do something
}
// determine something by calling methods within the same class
public boolean shouldSomethingBeDone() {
int result = 0;
if (isThisTrue("foobar")) {
doThis();
result = doThat();
}
return result > 0;
}
}
I'm trying to avoid having too much logic in one of my Controller classes that is calling a service. The only way I could see getting around this was by created a method such as the one above.
The dilemma arose when I tried to create a unit test and mock the calls within the shouldSomethingBeDone() method. Since all of the calls are to methods within the same class it's difficult to mock this.
Thanks.
Have you seen the Tell Don't Ask principle?
Methods like
isThisTrue
ask questions and push the logic for answering them all over the place. Instead, prefer to just tell the object what to do and let it worry about it.This suggests that instead of
shouldSomethingBeDone
you should rename the method to tell the object what to do instead (difficult without real names, but let's saydoSomething
is a better name).