Question

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

Was it helpful?

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

OTHER TIPS

Technically aren't you telling them to tell you something about themselves when you ask them about themselves?

OOP gives me a headache sometimes, I'm never sure when to stop thinking and start writing, or to stop writing and start thinking :X

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top