If you had an enormous number of if/ifelse/ifelse/.../else statements, something like this might help:
public interface Choice {
public boolean check(int value);
public void action(int value);
}
public class BelowRange implements Choice {
public static boolean check(int value) {
return (value < 10);
}
public void action(int value) {
// Do something;
}
}
public class Range1 implements Choice {
public boolean check(int value) {
return (value > 10 && value < 50);
}
public void action(int value) {
// Do something;
}
}
...
And in your code:
List<Choice> choices = new ArrayList<Choice>();
choices.add(new BelowRange());
choices.add(new Range1());
...
for (Choice choice : choices) {
if (choice.check(value)) {
choice.action(value);
}
}
I might implement it so the implementations of choice could be static methods, instead of having to instantiate them, but the gist of the thing is there.
If the compiler heavily optimizes this, especially with a static method, it shouldn't be slower at all, and it would make an enormously nested if/else structure a lot more maintainable from a developer's point of view.