- Tell your code to do something, don’t ask it for internal state
- Avoid low level details
Procedural code gets information then makes decisions. Object-oriented code tells objects to do things.
– Alec Sharpe, Smalltalk by Example
endeavor to tell objects what you want them to do; do not ask them questions about their state, make a decision, and then tell them what to do.
Making decisions outside the object violates encapsulation
An example from the Thoughtbot blog:
is_a? in Ruby is another type of tell-dont-ask violation.