Design Patterns · Senior · Question 32 of 75
What does the "Tell, Don't Ask" principle mean?
- ✓Correct answer: Ask an object to act instead of deciding for it
- 2Don't ask colleagues questions - read the documentation
- 3Log every action instead of returning values
Explanation
Instead of if (cart.items.length > 0 && !cart.locked) cart.items.push(x) - cart.add(x), with the rules inside. This keeps invariants close to the data and reduces "envious" functions.