Hexagonal architecture
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
place the domain at the centre and push frameworks to the edge.
Planned topics
- Ports are interfaces owned by the domain; adapters implement them for a technology.
- Driving (inbound) side: REST controller calls an inbound port (use case).
- Driven (outbound) side: the domain calls an outbound port (
PaymentGateway); an adapter talks to the real provider. - The dependency rule: adapters depend on the domain, never the reverse.
- Payoff: unit-test the domain without Spring, swap adapters freely.
- Do not add an interface where no boundary exists.
Draft outline details
Demonstration
// domain: no Spring, no JPA imports
public interface PaymentGateway { PaymentResult charge(OrderId id, Money amount); }
// adapter (infrastructure)
@Component class StripePaymentAdapter implements PaymentGateway { ... }Check your understanding
Who owns the PaymentGateway interface, the domain or the adapter?
Show answer
The domain.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.