How does the Hexagonal Architecture (Ports and Adapters) apply DIP?
Answer
Hexagonal Architecture (also called Ports and Adapters, coined by Alistair Cockburn) is DIP applied at the architectural level. The domain (core business logic) sits at the center and defines ports — interfaces describing what it needs from the outside world (persistence, messaging, external services). Adapters are concrete implementations of those ports — a MySQL adapter, a SendGrid adapter, a REST adapter. The direction of dependency is always inward: adapters depend on port interfaces; the domain depends on nothing outside itself. This means the domain is fully testable without any infrastructure, can be driven by multiple adapters simultaneously (REST API + CLI + message queue), and infrastructure can be swapped without changing domain logic. Laravel's repository pattern partially implements this; clean architecture frameworks go further.
Previous
How do you balance SOLID principles with pragmatic software development?
Next
What is the relationship between SOLID and Clean Architecture?
More SOLID Principles Questions
View all →- Advanced How do SOLID principles apply to domain-driven design?
- Advanced How do you balance SOLID principles with pragmatic software development?
- Advanced What is the relationship between SOLID and Clean Architecture?
- Advanced How does LSP interact with covariance and contravariance in type systems?
- Advanced How do SOLID principles apply to event-driven architectures?