数据访问:“告诉,不要问”的例外?

发布于 2024-07-30 03:03:30 字数 52 浏览 2 评论 0原文

数据访问对象是“告诉,不要问”规则的例外吗? 例如,从表数据网关获取最后 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-08-06 03:03:30

《告诉不要问》的一篇摘要说:

“你应该努力告诉对象你想让他们做什么;不要问他们关于他们状态的问题,做出决定,然后告诉他们做什么。”

在向数据对象询问信息的情况下,我认为我们没有违反该原则。

考虑显示包含“人员”信息的报告或 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".

羁绊已千年 2024-08-06 03:03:30

从技术上讲,当你询问他们自己时,你不是告诉他们告诉你一些关于他们自己的事情吗?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文