Abstraction hides selected implementation details behind a general concept. In data-oriented design, resist creating one before the data, ownership, and boundaries are clear. section 10.3.1 section 10.7
When flexibility damages a boundary
A FileRepository with separate loadAccounts, loadInvoices, and loadDisputes methods may look repetitive. Replacing them with a generic load method that accepts a parser appears flexible, but moves file-format knowledge into callers and weakens the repository boundary. The safer abstraction is usually over semantic data, not messy real-world parsing and operational behavior. section 10.4.4
Use abstraction deliberately:
- Study the data before grouping functionality or choosing reusable concepts. section 10.3.1
- Prefer abstractions over data, interpreters, and utility functions when they preserve clear architectural boundaries. section 10.4.4
- Treat extensibility as a cost rather than an automatic improvement; simple operations can remain simple. section 10.7
Listing 10.34 Well typed. Extensible. Flexible. What’s not to love?
void example(Manifest manifest) {
List<Account> accounts = fileRepo.load(
manifest.account, AccountParser::parse);
List<Invoice> invoice = fileRepo.load(
manifest.invoices, InvoiceParser::parse);
List<Dispute> dispute = fileRepo.load(
manifest.disputes, DisputeParser::parse);
}Compare the apparently flexible generic loader with its callers, which must supply representation-specific parsers and therefore absorb repository knowledge. section 10.4.4























