Design Patterns · Senior · Question 32 of 75

What does the "Tell, Don't Ask" principle mean?

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.

Further reading

Problem with a question

Design Patterns · Senior · question 32

Test yourself

Take the Design Patterns · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz