Reputation: 719
What do you think will be the best way to refactor this kind of boolean method?
if (someService.isTrue(importantArg)) {
return true;
} else if (someService.isSomeTrue(anotherArg)) {
return isAnotherCondition(entry);
} else {
return super.thisMethod();
}
Upvotes: 0
Views: 177
Reputation: 2208
This is a minor refactoring, but you can remove the elses as you can't reach that code if the previous condition was true (if it was true, it would have returned a value and exited the method)
if (someService.isTrue(importantArg)) {
return true;
}
if (someService.isSomeTrue(anotherArg)) {
return isAnotherCondition(entry);
}
return super.thisMethod();
Upvotes: 3
Reputation:
return someService.isTrue(importantArg) || (someService.isSomeTrue(anotherArg)
&& isAnotherCondition(entry)) || super.thisMethod();
Upvotes: 1