Repository Pattern, Revisited
Motivation
I first encountered the repository pattern in a Go backend codebase, where there are files/packages named “repo” and those packages are used to supply information from data sources. I was puzzled by such usage because until then, I have always known “repository” as a term related to “Git” and “GitHub”. With further research online, I then realized that the repository pattern is a popular abstraction layer between the business logic and the data sources.
A succinct description of the repository pattern by Edward Hieatt and Rob Mee ( P of EAA):
Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.
This pattern is often discussed when talking about Domain Driven Design, which is
an approach to software development that centers the development on programming a domain model that has a rich understanding of the processes and rules of a domain. — Martin Fowler DomainDrivenDesign
In this article, I hope to consolidate some of the excellent resources that discuss the repository pattern in-depth and provide my examples and reflections on this pattern.