4

如果我设计了如下所示的 AR,您认为我应该如何更新订单行对象之一中的属性?

例如,我如何更改我的订单行之一的标题(示例问题)

这是订单聚合根

public class Order
{
    private readonly int id;
    private readonly Customer customer; // Customer is another Aggregate
    private readonly IList<OrderLine> orderLines;
    private readonly IOrderLineFactory orderLineFactory;

    public Order(int id, Customer customer, IOrderLineFactory orderLineFactory)
    {
        this.id = id;
        this.customer = customer;
        this.orderLines = new List<OrderLine>();
        this.orderLineFactory = orderLineFactory;
    }

    public void AddOrderLine(Item item, int quantity)
    {
        OrderLine orderLine = orderLineFactory.Create(this, item, quantity);
        orderLines.Add(orderLine);
    }
}
4

1 回答 1

1
Order order = orderRepository.find(orderId);
order.changeTitle(orderLineId, "New title");

其中 'orderLineId' 可以是行号或索引或其他东西,只要它是特定于聚合根的(不是全局 id)。请参阅对类似问题的答案。

于 2012-07-30T19:18:23.540 回答