There is a concept that talks about the separation of the persistent layer
from the domain layer
to make the domain layer
more robust - it would not be dependent on the actual implementation of the repository in persistence layer
, but only on the repository interface.
It means that we have:
IPersonRepository {...} // in domain layer
PersonCassandraRepository implements IPersonRepository {...} // in persistence layer
Person (Aggregate Root) {...}
Now, what about Person
?
In anemic-domain-model
we can have:
IPerson {...} // in domain layer
Person implements IPerson {...} // in persistence layer
Why put Person in persistence layer?
Because it contains implementation-specific code.
For example, it may contain JPA-related annotations, and the same as with repository, we don't want data-store specific implementation in our domain layer.
We can do the above with anemic-domain-model, because Person does not contain any domain logic, which means we can put Person in persistene layer.
In anemic-domain-model data is separated from behavior, so Person's behavior is done by separated services, and not written in Person itself.
We cannot do this layers separation with rich-domain-model, because in this case, Person does contain domain-specific logic.
How would you do this layers separation within a rich-domain-model application?
Or maybe you are thinking that it is not needed.