Skip to content

Instantly share code, notes, and snippets.

@HenriqueSilverio
Created February 14, 2024 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HenriqueSilverio/03372e935ce1635e77d78cdc98ff81a9 to your computer and use it in GitHub Desktop.
Save HenriqueSilverio/03372e935ce1635e77d78cdc98ff81a9 to your computer and use it in GitHub Desktop.

Designing Repositories

  • 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.

References

  • DDD, Chapter 6: The Life Cycle of a Domain Object - Repositories - The Relationship with Factories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment