A catalog of code smells
On This Lesson 4 topics
The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.
In this lesson
recognize common smells and the fix for each.
Planned topics
- A smell is a hint of a problem, not a bug.
- Long method: extract smaller methods.
- Large class: extract a class.
- Feature envy: a method uses another class's data more than its own; move it there.
- Primitive obsession: using
Stringordoublefor ideas like money or email; make a small type (a record). - Duplicated logic: extract a method.
Draft outline details
Demonstration
// primitive obsession
void charge(double amount, String currency) { ... }
// better
void charge(Money amount) { ... }Check your understanding
Which smell is double price for money?
Show answer
Primitive obsession.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.