Design Patterns - Repository

A repository encapsulates the data access so the consumer on longer has to know about the underlying data structure

Why this Design is Problematic

  • The controller is tightly coupled with the data access layer
  • it is difficult to write a test for the controller without side effects
  • Hard to extend entities with domain specific behavior

Benefits of the Repository Pattern

  • The consumer(controller) is now separated (decoupled) from the data access
  • Easy to write a test without side-effects
    • In production, we use the Repository Pattern to communicate with the Data layer. In Test, we replace the Repository with a faked local Data store. This can be done using Strategy Pattern.
  • Modify and extend entities before they are passed on to the consumer
  • A sharable abstraction resulting in less duplication of code
  • Improved maintainability