A repository gives application code collection-like access to domain data while hiding how that data is stored. The abstraction is useful, but its shape should follow the domain and the storage system rather than an imagined future. section 5.1.3 section 10.4.7
Repository designs commonly expose these tensions:
- ORM-oriented designs often generate one repository or DAO per entity, with standard CRUD operations delegated to a service layer. section 5.1.3
- A repository can become an oversized file loader whose methods grow whenever a new data type appears; simple replacement may be preferable to speculative extensibility. section 10.4.5
- The repository understands storage constraints that application code may miss, such as fast primary-key retrieval versus slow full scans. section 10.4.7
A repository at the application boundary
class CustomerRepo { private DatabaseLib db; public Customer getById(String customerId) {...} public void save(Customer customer) {...} } A service can coordinate CustomerRepo, InvoiceRepo, RulesRepo, and FeesRepo, while each repository hides its particular data-access mechanism. If the database exposes get(primaryKey) and scan(expression), the repository can prevent callers from casually choosing an expensive scan. section 5.1.3 section 10.4.7
Table 10.2 Methods exposed for retrieving data
|
Method
|
Description
|
| TableRecord get( String primaryKey ) |
Retrieves
an item by its primary key. Fast.
|
| List<TableRecord> scan( PredicateExpr expression ) |
This is a
non-indexed crawl over every item in the database. Flexible, but slow.
|
Compare primary-key retrieval with non-indexed scanning to see why repository methods should reflect storage costs. section 10.4.7










