The Dependency Inversion Principle (DIP) is the SOLID design principle, attributed to Robert C. Martin, that high-level modules should not depend on low-level modules; both should depend on abstractions, and details should depend on abstractions, not the reverse. In practice dependencies are injected via interfaces. Business logic then survives a change of database or framework and can be unit-tested without running real external services.
SOLID-Dependency Inversion Principle
Details
- Full Name
-
SOLID Dependency Inversion Principle (DIP)
Intent:
High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details; details should depend on abstractions.
When to Use:
-
High-level business logic directly instantiates infrastructure classes
-
Changing a database or framework requires modifying business logic
-
Unit testing requires running actual external services
Prompt Example:
"Refactore diese Klasse nach dem SOLID-Dependency Inversion Principle, sodass die Abhängigkeiten über Interfaces injiziert werden."
Related Anchors:
-
SOLID Principles (Umbrella)
-
Hexagonal Architecture - Architectural application of DIP