SOLID & Design Patterns Interview Question #114
What is the Mapper pattern and when is mapping useful?
Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced
Quick Interview Answer
Mapping translates data between models that serve different responsibilities, such as API DTOs, application models, domain objects, and persistence representations. It prevents those boundaries from becoming the same model accidentally.
Detailed Explanation
Mapping translates data between models that serve different responsibilities, such as API DTOs, application models, domain objects, and persistence representations. It prevents those boundaries from becoming the same model accidentally.
Mapping can be manual or automated. Manual mapping is often clearer for important domain transitions, while mapping libraries can reduce repetitive property-copying when mappings remain simple and explicit.
Code Example
public static OrderDto ToDto(Order order)
{
return new OrderDto(
order.Id,
order.Customer.Name,
order.Total.Amount,
order.Status.ToString());
}