Articles → .NET DESIGN PATTERN → Data Transfer Objects (DTO) And How They Are Different From The Business Objects In C#
Data Transfer Objects (DTO) And How They Are Different From The Business Objects In C#
Business Objects (BO)
Click to Enlarge
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
- The properties with simple getter and setter
- Business logic inside the property
Data Transfer Objects (DTO)
Can We Use Bos As Dtos?
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public List<string> Addresses { get; set; }
}
public class PersonAddress
{
public int Id { get; set; }
public int PersonId { get; set; }
public string Address { get; set; }
}
- What if the Business Objects contain some business logic? Then every time we pass the Business Objects, the business logic will also be called. This will be an overhead.
- If the number of objects increases in the future, then additional classes will be passed and the code needs to be changed every time
public class PersonAddressDTO
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public List<string> Addresses { get; set; }
}