gpt4 book ai didi

domain-driven-design - 什么属于总根

转载 作者:行者123 更新时间:2023-12-03 08:47:59 25 4
gpt4 key购买 nike

这是一个实际的域驱动设计问题:

从概念上讲,我认为我已经有了聚合根,直到我要定义根为止。

我有一个Employee实体,它已显示为“聚合”根。在企业中,某些员工可以针对他们记录与工作有关的违规行为:

员工----- *违规

既然不是所有员工都受此约束,所以我认为违规行为不会成为员工汇总中的一部分,对吗?

因此,当我想与员工及其相关的违规行为一起工作时,某些服务是否将这两个单独的存储库交互?

最后,当我添加违规时,员工实体上是否有该方法?
谢谢您的帮助!

最佳答案

经过更多的研究之后,我认为我已经回答了我的问题。

保罗·斯托维尔(Paul Stovell)对DDD messageboard上类似问题的回答略有编辑。将“客户”替换为“员工”,将“订单”替换为“违规”,您就会明白。

Just because Customer references Order doesn't necessarily mean Order falls within the Customer aggregate root. The customer's addresses might, but the orders can be independent (for example, you might have a service that processes all new orders no matter who the customer is. Having to go Customer->Orders makes no sense in this scenario).

From a domain point of view, you can even question the validity of those references (Customer has reference to a list of Orders). How often will you actually need all orders for a customer? In some systems it makes sense, but in others, one customer might make many orders. Chances are you want orders for a customer between a date range, or orders for a customer that aren't processed yet, or orders which have not been paid, and so on. The scenario in which you'll need all of them might be relatively uncommon. However, it's much more likely that when dealing with an Order, you will want the customer information. So in code, Order.Customer.Name is useful, but Customer.Orders[0].LineItem.SKU - probably not so useful. Of course, that totally depends on your business domain.



换句话说,更新客户与更新订单无关。可以想象,订单或违反我的情况可以独立于客户/员工来处理。

如果违规有详细信息行,则违规和违规行将成为同一聚合的一部分,因为更改违规行可能会影响违规。

编辑**
在我的 Realm 中,最令人折服的是,违规行为没有任何表现。它们基本上是事件发生的记录。尚不确定其含义。

关于domain-driven-design - 什么属于总根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/836379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com