The use case is there is a set of methods which need to be executed based on whether the previous one has returned true
or not.
For example:
class Test {
boolean method1() {...}
boolean method2() {...}
boolean method3() {...}
...
void callAll() {
if(method1()) {
if(method2() {
if(method3() {
...
}
}
} else {
error();
}
}
}
There has to be an else
for all the if
s.
Is there a better way of handling this scenario?