I'm facing huge problems with nested if conditions in our core java application An abstract of code is as below....we can have nearly 20 nested if conditions can you tell me how to optimize this piece of code ?
what is a better way of avoiding this nested if conditions in java.i can have 20 nested if conditions and that could be a huge problem from design perspective of Java Application.
Please help with a solution in java Java Version 1.6
String condition = getCondition();
if (condition.equals(add)) { // add operation
add();
if (condition.equals(sub)) {// sub operation
sub();
if (condition.equals(div)) { //div operation
div();
if (condition.equals(cos)) { // cos operation
cos();
}
}
}
}
EDIT: I can have more mathematical operations say 20 more,will switch work then.20 operations is a huge lot.