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)




Picture showing the Person table
Click to Enlarge



public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
}




  1. The properties with simple getter and setter
  2. 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; }
}




  1. 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.
  2. If number of objects increases in the future, then additional classes will be passed and 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; }
}





Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, September 27, 2022

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250