2

'So it was in this context we created a Order.adjust() method that delegated the call to OrderAdjust Service. Having Order.adjust() has an advantage that it makes Order own the adjust operation.'

How is this done? Is the domain service injected?

$order = new Order();
$order->adjust(???);

How can the domain service do operations on domain entities when it's stateless? If a domain service is injected into an entity, methods can only be called on the reference and thus state must exist?

$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);

Shouldn't it be done like this or in an application service?

$domain_service = new DomainService();
$entity = new DomainEntity();
$another_entity = new AnotherDomainEntity();

$domain_service->performOperation($entity, $another_entity);

How are the operations between domain entities/objects done? How do domain objects in general communicate? Where are they instantiated?

Code examples would be greatly appreciated.

Source: http://stochastyk.blogspot.no/2008/05/domain-services-in-domain-driven-design.html

Seralize
  • 1,117
  • 11
  • 27
  • Is this homework? Why are you asking essay-type questions? And why are you asking three separate questions in one? – Todd A. Jacobs Jun 18 '12 at 05:28
  • This is not homework. I made structure for easy reading. The questions are related; I rather ask questions closely related in one post. Regarding the vote for closing: How should I ask this question properly? – Seralize Jun 18 '12 at 05:34

1 Answers1

1

The question is similar to this one: https://softwareengineering.stackexchange.com/a/62193/19252.

The blog post you referenced does a good job on your question. To make it short: If it can be done (and unit-tested!) in a model, do it there. Domain services are rather exception than a rule.

Let me quote that post:

"- Are'nt Services bad and should'nt we use all objects as per OO?

Yes, Services tend to stand orthogonal to Object Oriented Design. [...] There is a huge tendency in the modelling world to use excessive number of services"

As for me, the tendency comes from flaws of .NET/Java persistence architectures, like impossibility to put business logic into setter methods.

Community
  • 1
  • 1
Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91