![cover-img](https://project-assets.showwcase.com/1420x/16381/1671369974583-adarsh-kummur-zThTy8rPPsY-unsplash.jpg?type=webp)
Code Smell 36 - Switch/case/elseif/else/if statements
18 December, 2022
3
3
0
Contributors
Problems
•
Too many decisions together
•
Coupling
•
Duplicated code
•
Violation of Open/Closed Principle.
•
A new condition should not change the main algorithm.
•
Nulls
Solutions
1.
Polymorphism
2.
Create hierarchies/compose objects following Open closed principle.
3.
Use State pattern to model transitions.
4.
Use Strategy Pattern/Method Object to choose for branches.
Examples
•
Discrete Values
•
State transition
•
Algorithm choice.
Sample Code
Wrong
Right
Detection
Relations
More Info
Credits
If debugging is the process of removing software bugs, then programming must be the process of putting them in.