Repository


pattern architecture

Repository is a layer of abstraction for query construction. It is supposed to exist between domain objects and Data Mapper. As the name suggests, a repository behaves like a collection of objects in memory. Objects can be added and removed from the repository. Repositories should be defined only for aggregate roots.

Repository helps to separate query buildings from the domain layer. Because querying itself easily causes technical complexity, protecting the domain layer from it is a good idea.

See Also

References

  1. Eric Evans, Domain-Driven Design: Tackling Complexity in the Heart of Software, Six. The Life Cycle of a Domain Object, Repositories.
  2. Martin Fowler, Patterns of Enterprise Application Architecture, Chapter 13. Object-Relational Metadata Mapping Patterns, Repository.
  3. https://martinfowler.com/eaaCatalog/repository.html
  4. Hanami guides, https://guides.hanamirb.org/v1.3/repositories/overview/