I'm wondering where a switch statement of this style should be changed to an if else statement.
switch (foo) // foo is an enumerated type
{
case barOne:
if (blahOne)
{
DoFunction(//parameters specific to barOne);
break;
}
case barTwo:
if (blahTwo)
{
DoFunction(//parameters specific to barTwo);
break;
}
//etc.
default:
// Whatever happens if none of the case's conditionals are met
}
Basically fall through is happening unless a condition is met for one of the cases. The cases are very similar, differing only in what needs to be checked for and what needs to be passed, which is why I used a switch statement.
Would it be better to use if
else if
? Otherwise, is it clear enough to stay, but unclear enough to warrant a comment about the fallthrough? Polymorphism is also always an option, but it seems like overkill to me.