Posts

Showing posts from March, 2020

Repository Pattern

How can I explain the Repository Pattern to myself?
What is it? The core idea of the Repository Pattern is that it is a method of encapsulating data access and moving it away from your code. Allowing the rest of your code to talk to the database using the domain objects that are moved around through the rest of the application.

A good repository will only implement the functions that are required by its consumers rather than adding functions that would be nice to have but may never be used. If you never need to update an item don't have a method for it.
What is it used for? The Repository Pattern has several advantages:
Making code testable by encapsulating dependency on database This allows the Repository to be mocked out in unit tests allowing the tests to run quickly without requiring complex database set up and tear downs.
Mapping from data storage to domain objects Abstracting away the database means that complex data structures that may be used in storing the data only ne…