Teams can build frontend integrations and database schemas simultaneously by adhering to port definitions.
public class User private String username; private String password;
Let’s simulate a small snippet of what the PDF likely teaches using a banking example.
The book organizes software into three distinct logical "hexagons" to enforce separation of concerns: Domain Hexagon Teams can build frontend integrations and database schemas
: Acts as a middleman between business rules and the outside world. It uses (interfaces) and
// Getters and setters
to transform a modularized hexagonal application into a high-performance, cloud-native system. 3. Key Benefits for Developers Maintainability It uses (interfaces) and // Getters and setters
// Constructor injection (Spring 5+ / Boot 2.4+) public WithdrawController(WithdrawMoneyPort withdrawUseCase) this.withdrawUseCase = withdrawUseCase;
If your codebase looks like a framework with polite domain classes tucked inside, flip it: start with business rules and ask every dependency, “Is this a port or an adapter?” That discipline changes how teams reason about change, scaling, and long-term maintenance.
Adapters represent the implementation details. They translate data between external technologies and the formats required by your ports. Adapters represent the implementation details
(Note: OrderEntity and SpringDataOrderRepository would be standard Spring Data JPA classes located purely within the infrastructure adapter layer). Why Choose Hexagonal Architecture? Monolithic/Layered Architecture Hexagonal Architecture
package com.example.ordermanagement.domain.model; import java.math.BigDecimal; import java.util.UUID; public class Order private final UUID id; private final BigDecimal price; private boolean isPaid; public Order(BigDecimal price) this.id = UUID.randomUUID(); this.price = price; this.isPaid = false; validate(); private void validate() public void markAsPaid() this.isPaid = true; // Getters public UUID getId() return id; public BigDecimal getPrice() return price; public boolean isPaid() return isPaid; Use code with caution. 2. The Ports (Interfaces)
If you decide to switch your framework from Spring Boot to Quarkus, or your database from PostgreSQL to MongoDB, your core domain code remains entirely untouched. 2. Ports (The Gateways)
// Inside the hexagon: Core Java only package com.mybank.domain;