I'm developing a BlackBerry app in Java and I have an Options class where all user settings are stored. The problem is I need to check some conditions in order to know how to react. As I keep adding more features, more GUI options are shown to the user, more settings are stored in the Options class and more conditions need to be checked for.
Take the following code for example:
private void doCallMonitoring(int callId){
/*This is the part that I want to avoid. Having
multiple nested ifs. Here's just two conditions
but as I add more, it will get unmantainable
very quickly.*/
if(Options.isActive().booleanValue()){
callTime = new Timer();
TimerTask callTimeTask = new TimerTask(){
public void run(){
callTimeSeconds++;
if((callTimeSeconds == Options.getSoftLimit().intValue()) && (Phone.getActiveCall().getStatus() == PhoneCall.STATUS_CONNECTED)){
injectDTMFTone(Phone.getActiveCall());
}else if((callTimeSeconds >= Options.getHardLimit().intValue()) && (Phone.getActiveCall().getStatus() == PhoneCall.STATUS_CONNECTED)){
injectEndCall();
}
}
};
callTime.schedule(callTimeTask, 0,1000);
}else{
System.out.println("Service not active");
}
}
How I would want it to work is to verify all options with a single call and from there determine the curse of action. How can I achieve such a design?