Skip navigation.

Codemanship's Code Smell Of The Week - Switch Statements

Codemanship's Code Smell Of The Week - Switch Statements

Switch statements are bad from an OO design standpoint. Not only because they're basically big nested IF statements, but because they have a tendency to grow. A refactored switch statement would exploit polymorphism, which is the OO way to make decisions about how to do specific "stuff" at run time.

Jason Gorman demonstrates how he refactors a simple switch statement into a polymorphic OO solution (like the Strategy Pattern).

Part I