lundi 26 janvier 2015

Replacing if else statement with pattern

I have a if else statement which might grow in the near future.



public void decide(String someCondition){

if(someCondition.equals("conditionOne")){
//
someMethod("someParameter");

}else if(someCondition.equals("conditionTwo")){

//
someMethod("anotherParameter");

}
.
.
else{

someMethod("elseParameter");

}
}


Since, this is already looking messy, I think it would be better if I can apply any design patterns here. I looked into Strategy pattern but I am not sure if that will reduce if else condition here. Any suggestions?


Aucun commentaire:

Enregistrer un commentaire