-
FACTORIES and REPOSITORIES have distinct responsibilities.
-
A FACTORY’S job is to instantiate a potentially complex object from data. If the product is a new object, the client will know this and can add it to the REPOSITORY, which will encapsulate the storage of the object in the database.
-
The desire for “find or create” functionality [...] This function should be avoided. It is a minor convenience at best.
-
Usually, the distinction between a new object and an existing object is important in the domain, and a framework that transparently combines them will actually muddle the situation.
- DDD, Chapter 6: The Life Cycle of a Domain Object - Repositories - The Relationship with Factories