Knowledge
Search knowledge... ⌘K
Knowledge · Anti-Patterns
Smell Switch Statements
Anti-pattern indicating need for refactoring
Tags
refactoring-fowlercode-smellmaintainability
Impact
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.
Symptoms
- Switch statements that switch on type codes
- Same switch statement duplicated in multiple places
- Conditionals that determine behavior based on object type
Source
Martin Fowler — Refactoring: Improving the Design of Existing Code, 1st Edition (1999)