jargon

Comparison

Feature envyvsTell, don't ask

Feature envy

the method calls five getters on another object and one on itself, so it belongs on that other object.

A method more interested in another class's data than in its own, which is a signal that it is on the wrong class. Moving it puts the behaviour with the data it operates on, which usually lets several of those getters become private. It is the smell that tell-don't-ask is a rule about, and it is the easiest one to spot mechanically.

Full entry →

Tell, don't ask

the caller pulled three fields out, decided something, and wrote one back — a decision the object should have made itself.

The heuristic that you should send an object a message describing what you want done, rather than interrogating it and acting on its data from outside. It is the practical form of encapsulation: behaviour lives with the data it needs. The counterweight is that not everything is an object with behaviour — a value being reported to a user or serialised has to be asked for, and forcing it through a command is worse than the smell it avoids.

Full entry →

Related comparisons