Roadmap › Clean Code, Testing & Best Practices › Module: Code Smells and Refactoring
Lessons in this course (12)
5. Common code smells
Intermediate★ Must knowLesson 5 of 12
| Smell | Symptom | Refactoring |
|---|---|---|
| Long method | > ~30 lines, many comments explaining blocks | Extract Method |
| Large class / God class | Many responsibilities, 1000+ lines | Extract Class (SRP) |
| Long parameter list | 5+ params | Introduce Parameter Object |
| Duplicated code | Same logic in many places | Extract Method/Class, DRY |
| Switch on type | switch (type) repeated | Replace Conditional with Polymorphism (Strategy) |
| Feature envy | Method uses another class's data more than its own | Move Method |
| Primitive obsession | string email, decimal amount + string currency everywhere | Value objects (Email, Money) |
| Shotgun surgery | One change edits many files | Move related code together |
| Dead code | Unused methods/params | Delete |
| Magic numbers | if (status == 3) | Enum/constant |