I have in my code a nasty(or maybe not nasty?) method that contains multiple (9 to be exact) nr of if-statements. See below example. I'm trying to find a good pattern(perhaps?) to make the code more nice. Maybe 9 if-statements is ok but I see a potential risk that these statements can increase in the future. I've been looking at the strategy-pattern but don't really see it to be a good candidate. What pattern could be a good replacement for multiple if-statements?
if (text.Contains("aaa")) {
doA();
}
if (text.Contains("bbb")) {
doB();
}
... an so on.
Aucun commentaire:
Enregistrer un commentaire