Reusing one type for an API response, domain entity, and persistence record couples those concerns: a local change can ripple across the system. Mapping keeps each representation separate so changes stay at the boundary where they belong. section 5.4.1
Each layer has different needs: persistence uses mutable ORM objects, the domain uses objects with behavior, and APIs need consumer-shaped serializable data. Mapping costs effort to write and maintain, but prevents one representation from dictating changes across layers. section 5.4.1
Choose the amount of mapping at each boundary:
- No mapping couples representations; one-way mapping decouples the API. section 5.5
- Two-way mapping decouples API and persistence and is a pragmatic default; the Full Bridge isolates every boundary. section 5.5
Translate a neighbor’s model at the boundary before it reaches a use case. An outbound adapter maps a service response to the DTO declared by the local output port; an input adapter maps an incoming contract to a command or query. Map remote failures to local errors there as well. section 11.4 section 11.8
Table 11.1 Mapping the author-service response into WriteFlow’s model
|
Before
translation
|
After
translation
|
|
Author-service
response, in the author service’s model
|
DTO
declared by WriteFlow’s output port, in WriteFlow’s model
|
Shows an author-service response translated into the DTO owned by the local output port. section 11.4
