由两个聚合根引用的域对象
我为具有以下域对象的网站设计了一个模型:
文章>> 事件>> (比如节日,...) 评论>> (可以为文章和活动创建)
我应该将评论域对象放在模型中的什么位置? 它应该单独保留还是使用自己的聚合? 但如果没有文章或事件,评论就没有意义……
谢谢马里奥
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,DDD 不会阻止两个聚合根引用同一域对象。只要该对象不是两个聚合根边界的一部分。
在这种情况下,我会考虑创建一个
ArticleComment
和EventComment
对象,每个对象都属于其相关的聚合根。使用仅适用于所评论的一种类型的评论对象应该会更清楚。您仍然可以通过抽象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
andEventComment
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 abstractComment
class.