Skip to content
Ameen Abozaid
In reviewJNR-003-L05

A catalog of code smells

  • Lesson 5 of 7
  • 10 min read
  • Junior
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 String or double for ideas like money or email; make a small type (a record).
  • Duplicated logic: extract a method.
Draft outline details

Demonstration

java
// 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.