[TYPO3-50-general] FLOW3 and DDD

Xavier Perseguers typo3 at perseguers.ch
Mon Jan 19 16:14:15 CET 2009


Hi Nino,

>> 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.
> 
> I have this book and have read it.

Me too, recently.

> And I know of transient entities but in the following example you forgot 
> to mention some details.
> 
>> $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
> 
> Creating an entity Customer without identity is simply not possible.
> An entity without identity is a paradoxon. It may be a prototype or 
> something else but not "the" domain object.

Why not but I do not understand something a bit later.

> You forgot to mention that in Nilsson example there is only "create 
> new", but create new Customer means create one with clear identity.
> Without it: how can you add it to the repository when you don't know its 
> identity, how will you get it back? Therefore you first have to check if 
> one with that identity exists (via a repository).

This sounds OK but do you mean that this is not repository's work to 
provide an ID/identity? I mean I do not need any identity (I understand 
identity as the auto-increment field in a DB) to work with my domain, I 
just need "pointers". That is when I "create" a new Customer. I have to 
provide it's first name, last name and perhaps a business id if I need 
it but albeit from that, a new customer does not have any identity or 
business identity until it is persisted. I don't want to reserve a free 
id (auto-incremented in MySQL) from the DBMS nor do I want to create a 
business id (thus not in relation with DB-stuff) until I do something 
useful for my business with this customer. That is for the business ID 
until it orders something for instance.

> So, the example should read:
> $customer = new Customer(12345); // where 12345 is the identity, 
> something like UUID
> ($addressRepository->find(bla, blub);)
> none found
> $address = new Address(bla, blub); // again "bla/blub" is identity
> $customer->setAdress($adress);
> $customerRepository->add($customer);
> $persistenceManager->persistAll();

That is you must generate an ID for all "new" customers regardless of 
whether they will be persisted later? I do not understand. If you 
generate a UUID, that's fine, it's unique by design but what if you use 
a sequential business number?

Hoping I'll get some light on this topic :-)

-- 
Xavier Perseguers
http://xavier.perseguers.ch/en/tutorials/typo3.html


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