Difference between POCO and DTO model

Really i spend more time to understanding Poco and DTO with lot of confusion and questions. After understanding i decide to post immediately to my blog

POCO Model

What is POCO?

  • POCO stands for Plain Old CLR Object .It provides freedom to define object model in which objects does not inherit from specific base classes.
  • POCO data classes also known as persistence-ignorant objects, it refers to an object do not have any persistence concerns
  • It mainly have a control over implementation and design
  • A POCO is a BO (Business object). we can implement validation and any other business logic can occur here.
  • POCO have state and behavior.

What is Persistence ignorance in POCO

It means(layers) it does not dependent on the design of the database,ie., type of database,type of database object.

Example for POCO Model

public class Customer {
public int CustomerID
{ get; set; }
public string CustomerName
{ get; set; }
public string CustomerGender
{ get; set; }
}

What is DTO?

  • Stands for Data Transfer Object, its Main purpose is to transfer data.
  • It just stores data. It is a lightweight container used for transfer data between layers.
  • There will be no effect on application if entity changed or modified (based on the Database structure)

Example for DTO Model

public Customer()
{
CustomerID = Int_NullValue;
CustomerName= String_NullValue;
CustomerGender = String_NullValue;
Address = String_NullValue;
}
Difference between POCO and DTD

  • POCO has state and behavior,but DTD has only state ( it does not contain behavior ie., method)
  • POCO describes an approach to programming, where DTO is a pattern that is used to move data using objects.