Mapping data to and from APIs
When dealing with APIs that can be called by any system, there is one golden rule: we should never expose our internal objects to the callers. If we don’t follow this decoupling idea and, for some reason, need to change our internal data structures, we could end up breaking all the clients that interact with us. Both the internal data structures and the objects that are used to dialog with the clients must be able to evolve independently from one another.
This requirement for dialog is the reason why mapping is so important. We need to transform input objects of one type into output objects of a different type and vice versa. In this way, we can achieve two objectives:
- Evolve our internal data structures without introducing breaking changes with the contracts that are exposed to the callers
- Modify the format of the objects used to communicate with the clients without the need to change the way these objects are handled internally...