LLDbeginner
Repository Pattern
Repository abstracts persistence so domain code does not depend directly on SQL, ORM, or storage-specific details. It is common in clean architecture and domain-driven design.
Reading time
8 min
repositoryclean architecturedddpersistence
Why Repositories Help
Business logic should not care whether data lives in SQL, NoSQL, or memory. Repositories provide a stable contract to retrieve and persist domain entities.
Benefits
- Easier mocking in tests
- Cleaner separation of concerns
- Less storage detail leakage into domain code
Caution
Repositories should stay focused on persistence, not become giant service objects containing business logic.
Interview Tip
Use repository pattern when persistence matters but should stay behind an abstraction.