且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DDD:通过其身份引用聚合根内部的实体

更新时间:2023-02-13 12:32:13

我认为这种方法没有错:

In my opinion there is nothing wrong with this approach:

Order order = orderRepository.find(orderId);
order.updateQuantity(orderLineId, 2);

orderLineId是本地身份".它特定于聚集根,在根外部没有任何意义.您不必将其称为"id",它可以是"order line number".来自埃里克·埃文(Eric Evan)的书:

orderLineId is a 'local identity'. It is specific to aggregate root and does not make sense outside of it. You don't have to call it an 'id', it can be 'order line number'. From Eric Evan's book:

边界内的实体具有本地身份,仅在内部具有唯一性 聚集.

ENTITIES inside the boundary have local identity, unique only within the AGGREGATE.

...仅AGGREGATE根可以直接通过数据库查询获得.所有其他对象都必须通过关联遍历来找到.

...only AGGREGATE roots can be obtained directly with database queries. All other objects must be found by traversal of associations.