The "Two-Way" Mapping Strategy
Explore the two-way mapping strategy in hexagonal software architecture, where each layer maintains its own distinct model for cleaner separation. Understand how web, domain, and persistence layers map data between each other, promoting single responsibility and isolating concerns. Learn about the benefits like clear mapping roles and drawbacks including added boilerplate and potential domain model vulnerability to outer layer changes. This lesson helps you grasp the conceptual simplicity and practical challenges of two-way mapping to apply it effectively in your projects.
We'll cover the following...
A mapping strategy where each layer has its own model is what I call the “two-way” mapping strategy outlined in the figure below.
Two-way mapping
Each layer has its own model, which may have a structure that is completely different from the domain model.
The web layer maps the web model into the input model that is expected by the incoming ports. It also maps domain objects returned by the incoming ports back into the web model.
The persistence layer is responsible for a similar mapping between the domain model, which is used by the outgoing ports, and the persistence model.
Both layers map in two ...