koen
koen

Reputation: 13747

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?

Upvotes: 2

Views: 320

Answers (2)

Sneakyness
Sneakyness

Reputation: 5403

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

Upvotes: 3

djna
djna

Reputation: 55907

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

Upvotes: 8

Related Questions