vendredi 5 mai 2017

Design approach for multiple if else statement?

I have method which returns sql query as string. This method consider parameter 'level' , based on this parameter there are multiple if else statement like

   if(level.equals("A1")){
    // add some  field in query
   }
   else if (level.equals("A2"))
   {
    // add some  field  and logic in query
   }
   ..

   so on 

In future number of levels are going to increase and I don`t want to write pesky if else statements so I am looking for cleaner and maintainable design approach for this scenario. I am thinking of strategy design pattern but not sure whether it is best for this scenario.

Aucun commentaire:

Enregistrer un commentaire