High-level classes should not depend on low-level classes; both should depend on abstractions. Abstractions should not depend on details; details should depend on abstractions. This inverts the typical direction of dependency so that business logic is insulated from changes in infrastructure.
Examples:
- A
BudgetReportclass that directly uses aMySQLDatabaseclass breaks whenever the database changes. Introduce aReportingStorageinterface declared in the business-logic layer.BudgetReportdepends on the interface;MySQLDatabaseimplements it. A later switch to PostgreSQL only requires a new implementation —BudgetReportis untouched.
Synonyms: dip