Tuesday, 22 March 2022

Repository Pattern

 # Repository Pattern

1. Repository Pattern is an abstraction of the Data Access Layer. It hides the details of how exactly the data is saved or retrieved from the underlying data source.
2. The details of how the data is stored and retrieved is in the respective repository.
3. For example, you may have a repository that stores and retrieves data from an in-memory collection. You may have another repository that stores and retrieves data from a database like SQL Server.


## Repository Pattern Interface specifies

1. What operations (i.e methods) are supported by the repository
2. The data required for each of the operations i.e the parameters that need to be passed to the method and the data the method returns
3. The repository interface contains what it can do, but not, how it does, what it can do
4. The implementation details are in the respective repository class that implements the repository Interface

## Benefits of Repository Pattern

1. The code is cleaner, and easier to reuse and maintain.
2. Enables us to create loosely coupled systems. For example, if we want our application to work with oracle instead of sql server, implement an OracleRepository that knows how to read and write to Oracle database and register OracleRepository with the dependency injection system.
3. In an unit testing project, it is easy to replace a real repository with a fake implementation for testing.


No comments:

Post a Comment

Search This Blog

Creating your first "Alexa" Skill

Index What is Alexa What is Alexa Skill? Why is it required when Alexa already equipped with voice assistant? Dev...