|
|
|
|
|
by masklinn
1673 days ago
|
|
> - "Often you find the same switch statement scattered about a program in different places. If you add a new clause to the switch, you have to find all these switch, statements and change them. The object-oriented notion of polymorphism gives you an elegant way to deal with this problem." -- fair enough Even that seems like it could easily be way overkill e.g. if you have multiple switches which, say, generate a label from an enum, the first step is probably to add a utility function / method, not to migrate the whole thing over to polymorphism. Although there is one thing to be said about context: * OP works in C#, whose enums are literally useless (they’re like C’s) * apparently even in Java (which at least has type-safe enums even if not sum types), `switch` is unable to check for completeness |
|