'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