Repaso
EspaƱol
Design & PracticesIntermediateDP-08

What problem does the Repository pattern solve?

Options

  1. Version control of the source code of a software project
  2. Hiding persistence behind a collection-like interface (Correct option)
  3. Caching HTTP responses to reduce the load on the server
  4. Managing package dependencies between the modules

Answer

Hiding persistence details behind a collection-like interface so domain logic does not depend on the ORM/SQL

Why

A repository is a class like UserRepository with simple methods: get(id), add(user), list_active(). All SQL or ORM code lives inside it.

The business logic only talks to the repository, so it does not care whether data comes from PostgreSQL, an API or a dictionary in memory.

In tests, you swap in an in-memory repository: fast and no database needed.

Remember

Repository = a clean door between business logic and the database.

Key terms

Practice this question in Repaso