Repository Layer
The repository layer isolates database access behind a dedicated interface so services and controllers can stay focused on business logic.
- Explain the purpose of the repository layer in a layered architecture.
- Describe how repositories interact with entities and services.
- Recognize why data access should be separated from business rules.
Repositories provide a clean boundary for saving, finding, updating, and deleting data.
A service can call a repository without knowing the underlying SQL or persistence details.
Repository interfaces are often implemented by Spring Data JPA, which reduces boilerplate.
This separation makes the application easier to test and easier to maintain.
A student management system uses StudentRepository to save student records, find a student by matric number, and delete inactive accounts without putting SQL in the controller.
- Why should database access live in a repository layer?
- How does a repository help keep the rest of the app simpler?
- Repositories hide persistence details.
- Services call repositories to work with data.
- Loose coupling improves testing and maintenance.