2012-06-18 90 views
1

'因此正是在這種情況下,我們創建了一個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

+0

這功課嗎?你爲什麼要問散文型問題?你爲什麼在一個問題中提出三個不同的問題? –

+0

這不是家庭作業。我製作了便於閱讀的結構。這些問題是相關的;我寧願在一篇文章中提出密切相關的問題。關於結束投票:我應該如何正確地提出這個問題? – Seralize

回答

1

的問題是與此類似:https://softwareengineering.stackexchange.com/a/62193/19252

你引用的博客文章在你的問題上做得很好。簡短說明:如果可以在模型中完成(並進行單元測試!),請在此處執行。域服務比規則更爲例外。

讓我引用該職位:

「 - Are'nt服務不好,我們should'nt使用的所有對象按照OO

是,服務往往站在垂直的對象[...]在建模領域有一個巨大的趨勢,使用過多的服務「

至於我,傾向來自.NET/Java持久性架構的缺陷,如不可能把業務日誌集成到setter方法中。

相關問題