0Pricing
PHP Academy · Lesson

Dependency Inversion in Practice

Wire adapters to the core with dependency inversion.

Inversion vs Injection

People conflate two distinct ideas. Dependency Injection is a technique: pass collaborators in rather than constructing them. Dependency Inversion (the D in SOLID) is a principle: high-level policy and low-level detail both depend on an abstraction, and the abstraction is owned by the high-level module. This lesson is about making the second one real — wiring concrete adapters to a core that defines the interfaces.

The Principle, Precisely

DIP states:

  • High-level modules should not depend on low-level modules. Both depend on abstractions.
  • Abstractions should not depend on details. Details depend on abstractions.

The subtle part: the interface belongs to the consumer, not the implementer. Your domain declares PaymentGateway; the Stripe adapter conforms to it — not the other way around.

All lessons in this course

  1. From Layered to Clean Architecture
  2. Ports and Adapters Explained
  3. Use Cases and Application Services
  4. Dependency Inversion in Practice
← Back to PHP Academy