数据访问:“告诉,不要问”的例外?
数据访问对象是“告诉,不要问”规则的例外吗? 例如,从表数据网关获取最后 10 个帖子?
Are data access objects an exception to the rule 'Tell, don't ask'?
Eg get last 10 posts from a table data gateway?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
《告诉不要问》的一篇摘要说:
“你应该努力告诉对象你想让他们做什么;不要问他们关于他们状态的问题,做出决定,然后告诉他们做什么。”
在向数据对象询问信息的情况下,我认为我们没有违反该原则。
考虑显示包含“人员”信息的报告或 UI。 除了问“你叫什么名字?”之外,我没有其他选择。 请注意,我们不会跟进任何“告诉他们该怎么做”。
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".
从技术上讲,当你询问他们自己时,你不是告诉他们告诉你一些关于他们自己的事情吗?
OOP有时让我头疼,我永远不知道什么时候该停止思考并开始写作,或者停止写作并开始思考:X
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