边界类可以与实体类交互吗?

发布于 2024-09-30 23:42:23 字数 171 浏览 3 评论 0原文

例如: link

以上是确定还是最好在控制器中创建更多方法来处理在 UI 和实体之间没有交互的情况下发送/检索的数据?

一般来说,什么时候允许(如果允许)边界类与实体类交互?

For instance: link

Is the above Ok or it would be better to create more methods in Controller that handle the data that are sent/retrieved without the interaction between UI and the Entity?

In general when is it allowed (if it is) for a Boundary Class to interact with an Entity Class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

·深蓝 2024-10-07 23:42:23

取决于您是否想要/需要严格遵守边界控制实体模式:

这并不意味着油嘴滑舌。这种严格的分离是否是良好的设计实践值得怀疑。它在图片中看起来很不错:边界、控制和实体位于漂亮的水平层中,消息仅传递相邻层。

现实却截然不同。严格分离可能会导致两个问题:

  1. 传递方法的激增。你提到这一点。您最终会在控制器上合并一些方法,这些方法除了传递到底层实体之外什么也不做。
  2. 贫血实体类。实体不再是数据+行为的家,而是成为数据容器,所有行为都迁移到控制器。这不是一件好事

值得注意的是,在域驱动设计中,Eric Evans 建议仅当相关逻辑不存在时才创建服务(类似于控制器)。在任何域类(实体)中都没有可行的家。

Depends on whether you want/need to stick religiously to the Boundary-Control-Entity pattern:

  • If yes (you do need to stick to the pattern): then no, the Boundary object can only speak to Control objects. See table at bottom of this page (also a good description of pattern).
  • If no: then yes it can!

That's not meant to be glib. It's questionable whether such strict separation is good design practice. It looks nice in pictures: Boundary, Control and Entity in nice horizontal layers with messages passing adjacent layers only.

The reality is rather different. Strict separation can lead to two problems:

  1. A proliferation of pass-through methods. You allude to this. You end up with an amalgamation of methods on the controllers that do nothing more than pass through to the underlying entities.
  2. Anaemic Entity classes. Rather than the Entities being home for data + behaviour, they become data containers only with all behaviour migrating out to controllers. That's not a good thing.

It's notable that in Domain Driven Design, Eric Evans recommends creating Services (akin to Controllers) only when the logic in question doesn't have a viable home in any of the Domain Classes (Entities).

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