由两个聚合根引用的域对象

发布于 2024-10-08 09:00:46 字数 174 浏览 0 评论 0原文

我为具有以下域对象的网站设计了一个模型:

文章>> 事件>> (比如节日,...) 评论>> (可以为文章和活动创建)

我应该将评论域对象放在模型中的什么位置? 它应该单独保留还是使用自己的聚合? 但如果没有文章或事件,评论就没有意义……

谢谢马里奥

i have designed a model for a website with the following domain objects:

Article <>
Event <> (like festival, ...)
Comment <> (can be created for articles and events)

Where do i put the Comment-Domain Object in the model?
Should it stay alone or use it's own aggregate?
But a comment makes no sense without an article or an event....

Thanks Mario

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

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

发布评论

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

评论(1

猫卆 2024-10-15 09:00:46

首先,DDD 不会阻止两个聚合根引用同一域对象。只要该对象不是两个聚合根边界的一部分。

在这种情况下,我会考虑创建一个 ArticleCommentEventComment 对象,每个对象都属于其相关的聚合根。使用仅适用于所评论的一种类型的评论对象应该会更清楚。您仍然可以通过抽象 Comment 类来强制执行通用数据和行为。

Firstly DDD doesn't prevent two aggregate roots to reference the same domain object. As long as the object is not part of both the aggregate root boundaries.

In this case I would consider to create an ArticleComment and EventComment objects, each belonging to their relevant aggregate roots. This should be clearer working with a comment object that only applies to one type being commented on. You can still enforce common data and behaviour by having an abstract Comment class.

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