← All Quizzes
What is the Repository pattern and why is it used?
Explanation
The Repository pattern abstracts data persistence, providing a collection-like interface for accessing domain objects. It mediates between the domain and data mapping layers, decoupling business logic from data access details (SQL, ORM, API). Benefits: centralized data access logic, easy testing (mock the repository), consistent querying interface, and swappable persistence implementations. Repositories are a key pattern in Domain-Driven Design and Clean Architecture. They typically expose methods like findById, save, delete, and findByCriteria, returning domain objects rather than raw data.