处理 DDD 中的嵌套聚合

发布于 2024-08-20 02:16:35 字数 839 浏览 9 评论 0原文

我刚刚开始使用 DDD,并且在弄清楚如何适应数据的关系性质时遇到了一些困难。我拥有我相信会被视为我的聚合根的东西,但聚合也有它自己的聚合。不想违反德墨忒尔定律,我想知道我的想法是否错误,并希望一些 DDD 专家可以提供一些见解。

我的聚合根是我的 Account 对象,它聚合了许多 AccountElement 实体,这些实体本身就是各个 ProductComponent 实体的逻辑分组。

Account 上下文之外的 AccountElement 没有任何意义,因此我对以下结论感到满意:Account 对象是我的聚合根,并且我预计该实体具有聚合 Elements 属性。让我感到困惑的是 ProductComponent 集合。此聚合在 AccountElement 之外没有任何意义,并且确实Account 之外也没有任何意义。

我认为我不应该通过点化方式来访问单个 ProductComponent 对象,例如:

var reference = account.Elements(0).ProductComponents(0).ReferenceCode;

但同时(从域的角度来看)访问 是没有意义的>ProductComponent 直接来自 Account 实体。

我确信如果不了解我的领域,这一切都有点难以理解,但我希望这足以获得一些好的反馈。

I'm just getting started in DDD, and I'm having some trouble figuring out how to accommodate the relational nature of my data. I have what I believe would be considered my aggregate root, but the aggregate also has an aggregate of its own. Not wanting to violate the Law of Demeter, I'm wondering if I'm thinking about this wrong and am hoping that some DDD expert can offer some insight.

My aggregate root is my Account object, which has an aggregate of numerous AccountElement entities, which are themselves logical groupings of individual ProductComponent entities.

An AccountElement outside of the context of an Account has no meaning, so I'm comfortable with my conclusion that the Account object is my aggregate root, and I anticipate that entity having an aggregate Elements property. It's the ProductComponent collection that has me confused. This aggregate has no meaning outside of an AccountElement, and really has no meaning outside of an Account.

I don't think I should be accessing individual ProductComponent objects by dotting my way to it, like:

var reference = account.Elements(0).ProductComponents(0).ReferenceCode;

But at the same time it doesn't make sense (from a domain perspective) to access a ProductComponent directly from an Account entity.

I'm sure that this is all a little difficult to comprehend without knowledge of my domain, but I'm hoping it's enough to get some good feedback.

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

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

发布评论

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

评论(1

预谋 2024-08-27 02:16:35

罗伯特链接的文章是一篇很好的文章。我想补充一点,如果 ProductComponent 仅存在于 AccountElement 的上下文中,并且 AccountElement 仅存在于 Account 的上下文中,那么通过扩展,ProductComponent 就存在于 Account 的上下文中。

The article Robert linked to is a good one. I would add that if ProductComponent exists only in the context of AccountElement and AccountElement exists only in the context of Account, then by extension ProductComponent is in the context of Account.

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