DDD建模,聚合根之间的交互 [英] DDD modeling, interaction between aggregate roots

查看:851
本文介绍了DDD建模,聚合根之间的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用1; 2; 3标记我的聚合根.看起来很不错-几乎像葡萄.

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

我不喜欢的是带有红色箭头标记的实体.

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

让我们想象一下:

  • AR#1是公司
  • AR#2是办公室
  • AR#3是员工
  • 标有红色箭头的实体名为Country
    • 公司设置从哪个国家雇用员工的规则(雇用时,company.Countries.Contains(employee.Country)必须为真)
    • 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)

      我不知何故看到了域的这一非常不重要的部分(也许在本例中听起来不是这样),并且我想避免促进Country聚合根.

      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.

      词汇表表示:

      对内部成员的临时引用只能传递给单个操作使用.

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

      那么-引入"EmployeeCountry"之类的内容,删除对公司所在国家/地区的引用并检查员工所在国家/地区是否在雇用操作上与任何公司所在国家/地区听起来合理吗?

      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?

      还有其他想法吗?

      我如何使我的葡萄看起来像它们应该的样子?

      How can I get my grapes look like they should?

      推荐答案

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

      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.

      您可以在Evans的域驱动设计"(也称为"蓝皮书).例如,请参见第127页的图(在聚合根的简介中),该图显示了具有对Engine聚合的引用的Car聚合.

      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.

      这篇关于DDD建模,聚合根之间的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆