10

Data Clumps


Symptom

The same group of fields travels together everywhere — (street, city, zip), (start, end), (firstName, lastName) — appearing as parameters, fields, or method args.

Goal

The clump becomes a value object with its own name and its own behavior.

Smellier version
function send(name, email, street, city, zip) {
  // ...
}
Fresher version
class Address { /* street, city, zip */ }
function send(name, email, address) {
  // ...
}
Savings

Operations on the clump (formatting, validation, equality) live with it; method signatures shrink.

Note

Adding or removing a field of the clump means touching every site; the clump's identity is invisible.