'因此正是在這種情況下,我們創建了一個Order.adjust()
方法,將呼叫委託給OrderAdjust Service
。 擁有Order.adjust()
有一個好處,它使得Order
擁有調整操作。域對象和服務如何在DDD中進行交互?
這是如何完成的?域服務是否注入?
$order = new Order();
$order->adjust(???);
域服務在無狀態時如何對域實體執行操作? 如果一個域服務被注入到一個實體中,只能在該引用上調用方法,並且狀態必須存在?
$service = DomainService();
$entity = DomainEntity();
$entity->operation($service);
// Inside DomainEntity
public function operation(DomainService &$service)
{
// Operations are delegated to the domain service reference
$service->operation();
$service->operation2();
}
$another_entity = AnotherDomainEntity();
// What happened in the first object must be known here
// otherwise what's the point?
$another_entity->operation($service);
不應該這樣做,或在應用程序服務?
$domain_service = new DomainService();
$entity = new DomainEntity();
$another_entity = new AnotherDomainEntity();
$domain_service->performOperation($entity, $another_entity);
域實體/對象之間的操作是如何完成的? 域對象一般如何通信?他們在哪裏實例化?
代碼示例將不勝感激。
來源: http://stochastyk.blogspot.no/2008/05/domain-services-in-domain-driven-design.html
這功課嗎?你爲什麼要問散文型問題?你爲什麼在一個問題中提出三個不同的問題? –
這不是家庭作業。我製作了便於閱讀的結構。這些問題是相關的;我寧願在一篇文章中提出密切相關的問題。關於結束投票:我應該如何正確地提出這個問題? – Seralize