Repository Pattern And Generic Repository Pattern

In this article, I will demonstrate you what repository pattern is and what are the benefits of repository pattern. I will also explain the generic repository pattern with their advantage.

I believe you all know the concept behind DRY. DRY stands for Don’t Repeat Yourself. It is a principal for OOPs. Nowadays with enterprise project which can be multi-tier architecture or multi-layer architecture, their is a need to implement DRY.

We can implement the features of DRY using the Repository Pattern.

Repository Pattern


Sometimes, it is required to define some logic between our business logic and data access logic. That logic can be defined using Repository pattern. Basically Repository pattern is a mediator between two layers. Repository pattern are mostly used where we need to modify the data before passing to the next stage.

Benefits of Repository Pattern

  1. It centralizes data logic or business logic and service logic.
  2. It gives a substitution point for the unit tests.
  3. Provides a flexible architecture.
  4. If you want to modify the data access logic or business access logic, you don’t need to change the repository logic.

    Repository Pattern

Generic Repository Pattern

Sometimes, it is required or it is best to make all the repository logic in one place using the generic logic. We can create only one repository class which will be responsible to handle the entire scenario. It can be a logic between repository and data access or it can be a logic between business logic and repository. In all cases we only write single repository. The main benefit of Generic Repository Pattern is reusability of code.

Benefits of Generic Repository Pattern

  1. It reduces redundancy of code.
  2. It force programmer to work using the same pattern.
  3. It creates possibility of less error.
  4. If you use this pattern then it is easy to maintain the centralized data access logic.

    Repository

Thanks for reading the article.

Up Next
    Ebook Download
    View all
    Learn
    View all