0
考慮以下情形:DDD - 通過聚合獲取實體,在aggegrate方法後面調用方法或隱藏實體方法?
class Order:
def __init__(self):
self.lines = []
def order(self, product_id, amount, price, discount=None):
item = OrderItem(product_id, amount, price)
self.lines.append(item)
class OrderItem:
def __init__(self, product_id, amount, price, discount=None):
self.product_id = product_id
self.amount = amount
self.price = price
self.discount = discount or decimal.Decimal(0)
def discount(self, amount):
self.discount = discount
在我們想要的折扣添加到特定行項目的情況下,Order
總量已創建後,我需要從總量得到OrderItem
實體,或暴露聚合方法?
E.g.
class Order:
...
def discount_item(self, index, amount):
self.lines[index].discount(amount)
如果我可以調用OrderItem.discount()
直接 - 我怎麼跟蹤出版作爲一個結果域的事件?