Search code examples
oopprinciples

data access: exception to 'Tell, don't ask'?


Are data access objects an exception to the rule 'Tell, don't ask'? Eg get last 10 posts from a table data gateway?


Solution

  • One summary of Tell Don't Ask says:

    "you should 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."

    In the case of asking a data object for information I don't think we violate that principle.

    Consider displaying a report or UI with "Person" information. I don't see much alternative to saying "What's your name?" Note that we don't follow up with any "tell them what to do".