[TYPO3-50-general] FLOW3 and DDD

Robert Lemke robert at typo3.org
Mon Jan 19 13:36:21 CET 2009


Hi Nino,

Am 19.01.2009 um 11:51 schrieb Nino Martincevic:

>> So conceptually a class annotated as @entity is always a member of an
>> aggregate. But it doesn't mean that it will be persisted (that's only
>> the case if it has a connectino to a repository).
>
> Hm, that seems to be a conceptual problem, though I'm not aware of the
> whole current architecture and the next statement shows me that you  
> have
> probably already thought of it.
> You said:
> "Therefore if you create an entity or value object, it will only be
> persisted if it is connected to an aggregate (an thus a repository)."
>
> That's exactly the point.
>
> I guess we agree that an entity is always part of an aggregate.
> As you stated right (and a bit extended here) the only way to access  
> an
> entity in DDD is through an aggregate (root) and an aggregate is only
> accessible through a repository.
> So, there can't be any entity instance not "directed" (created or  
> saved)
> by a repository.

There can be Domain Objects without connection to the repository which  
are then
not persisted. I call them "Transient Entities".

Do you've got a copy of Jimmy Nilsson's "Applying Domain-Driven Design
and Patterns"? Check out p. 281, the table which gives a summary of
the Semantics for the Life Cycle of Domain Model instances.

$customer = new Customer;            // $customer is a Transient Entity
$customerRepository->add($customer); // $customer added to the  
repository
$persistenceManager->persistAll();   // $customer becomes a Persisted  
Entity

$address = new Address;              // $address is transient
$customer->setAddress($address);     // $address now has connection to a
                                         repository through the  
Customer Aggregate

$persistenceManager->persistAll();   // $address will be persisted

> <Excursion>
> Well actually not in DDD sense but in the current infrastructure and
> technical solution of Flow3. Because some DDD guys even don't do that
> with repositories, just maintaining the lifetime of living entities,
> keeping it completely peristance ignoring. A domain model should be  
> that
> for being "perfect" but we also have to face the facts. And they are
> that there will be some persistence at some point.
> But I'm with you regarding this issue, my repositories also "save"...
> </Excursion>

The Domain Model is completely Persistence Ignorant. We weave in some
persistence code through AOP.

> On the other side perhaps you don't need to change anything. Because  
> if
> someone wants to create an non-root entity bypassing the repository  
> and
> aggregate he may do so for whatever reasons.

Yes, for example you'll want to create a Customer object without  
persisting
it until it's valid. Imagine a multi step form which carries a  
Customer in
a session until the form is finally submitted.

> But if he wants that entity
> to be persisted he has to add it to a aggregate/repository and he  
> has to
> do it with the provided methods of the aggregate root.

In fact there is nothing such an Aggregate object or Aggregat Root  
object
in FLOW3. Aggregates merely exist as a concept.

In the above example we have a Customer Repository and the Customer  
entity
automatically serves as an aggregate root. Address is part of the  
Customer
aggregate (in that example at least).

> Perhaps you could use an @aggregate annotation (if you don't have it
> already). That way you could avoid non-root entities to be created
> outside an aggregate, at least conceptually.

See above - there's no Aggregat class / object.

Cheers,
robert



More information about the TYPO3-project-5_0-general mailing list