LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 8

What does "tell, don't ask" mean? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What does the "tell, don't ask" principle recommend?

  • A Never write getters
  • B Tell objects what to do (account.withdraw(500)) instead of asking for their data and deciding outside (if (a.balance() >= 500) a.set_balance(…)) Correct
  • C Use exceptions instead of return values
  • D Prefer global functions
Correct Answer: Option B

The decision then lives next to the data it depends on, in one place.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links