DDD建模,聚合根之间的交互

发布于 2024-09-15 07:05:54 字数 779 浏览 3 评论 0原文

替代文字 用 1;2;3 标记我的聚合根。看起来很漂亮——几乎像葡萄。

alt text

我不喜欢的是一个用红色箭头标记的实体。

让我们想象一下:

  • AR #1 是公司
  • AR #2 是办公室
  • AR #3 是员工
  • 用红色箭头标记的实体名为 Country
    • 公司制定从哪些国家/地区雇用员工的规则(在雇用时,company.Countries.Contains(employee.Country) 必须为 true)

我以某种方式认为域的这个相当不重要的部分(也许在这个例子中听起来并不像1),我想避免将国家推广为聚合根。

关于聚合根的词汇表说:

对内部成员的临时引用只能传递出去以供在单个操作中使用。

那么,引入“员工国家/地区”之类的内容、删除对公司国家/地区的引用并检查员工所在国家/地区是否与招聘操作中的任何公司国家/地区相匹配,听起来合理吗?

还有其他想法吗?

我怎样才能让我的葡萄看起来像应有的样子?

alt text
Marked my aggregate roots with 1;2;3. Looks quite nice - almost like grapes.

alt text

Thing I dislike is an entity that's marked with red arrow.

Let's imagine that:

  • AR #1 is company
  • AR #2 is office
  • AR #3 is employee
  • Entity marked with red arrow is named Country
    • Company sets the rules from which countries it hires employees (on hiring, company.Countries.Contains(employee.Country) must be true)

I somehow see this quite unimportant part of domain (maybe it does not sound like that in this example one), and I would like to avoid promoting Country to aggregate root.

Glossary about aggregate roots says:

Transient references to the internal members can be passed out for use within a single operation only.

So - does introducing something like 'EmployeeCountry', removing reference to company Country and checking if Employee country matches any company country on hiring operation sounds reasonable?

Any other ideas?

How can I get my grapes look like they should?

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

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

发布评论

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

评论(1

浮云落日 2024-09-22 07:05:54

在这种情况下,Country 只是一个值对象,而不是一个实体 - 更不用说聚合根 - 因此没有理由更改您的设计的任何内容(没有更多信息)。

此外,请注意,您引用的警告涉及聚合根的内部成员,而不是聚合本身。在多个地方维护对聚合的引用并没有什么问题。聚合根应该封装子对象,以便有一个地方可以为相关对象强制执行业务规则。

您可以在 Evans 的“领域驱动设计”(又名“蓝皮书”中的多个地方清楚地看到这一点) )。例如,请参阅第 127 页上的图表(在聚合根的介绍中),该图显示了具有对 Engine 聚合的引用的 Car 聚合。

In this context Country is just a value object, not an entity - much less an aggregate root - so there's no reason to change anything about your design (without more information).

Additionally, note that the warning you cite pertains to internal members of aggregate roots, not aggregates themselves. There's nothing wrong with maintaining references to aggregates in multiple places. Aggregate roots are supposed to encapsulate child objects so that there's a single place to enforce business rules for related objects.

You can see this clearly in several places in Evans' "Domain-Driven Design" (a.k.a., "The Blue Book"). For example, see the diagram on page 127 (in the introduction to aggregate roots), which shows a Car aggregate that has a reference to an Engine aggregate.

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