The “Two-Way” mapping strategy
A mapping strategy where each layer has its own model is what I call the “Two-Way” mapping strategy, as outlined in Figure 9.2.
Figure 9.2 – With each adapter having its own model, the adapters are responsible for mapping their model into the domain model and back
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 directions, hence the name “Two-Way” mapping.
With each layer having its own model, it can modify its own model without affecting the other layers (as...