Junior
What is a DTO (Data Transfer Object)?
sobes.tech AI
Answer from AI
DTO (Data Transfer Object) is a simple object designed for transferring data between subsystems or processes. It does not contain business logic, only properties for storing data. It is used to reduce overhead in remote calls and improve serialization.
Main characteristics of DTO:
- Simple structure, usually containing only public properties.
- No business logic.
- Used for aggregating data from different sources or transferring a subset of data.
- Helps avoid over-fetching or under-fetching data during transfer.
Example of DTO:
// DTO for transferring user information
public class UserDto
{
public int Id { get; set; }
public string Username { get; set; }
public string Email { get; set; }
}