SOLID & Design Patterns Interview Question #112

What is the Data Transfer Object (DTO) pattern?

Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced

Quick Interview Answer

A DTO is an object designed to transfer data across application or process boundaries without exposing internal domain or persistence objects directly. DTOs usually contain data rather than domain behavior.

Detailed Explanation

A DTO is an object designed to transfer data across application or process boundaries without exposing internal domain or persistence objects directly. DTOs usually contain data rather than domain behavior.

Separate DTOs can stabilize API contracts, prevent over-posting, shape data for specific clients, and avoid serializing navigation properties or internal implementation details.

Code Example

public sealed record OrderDto(
    Guid Id,
    string CustomerName,
    decimal Total,
    string Status);