RajasekharwhY / Build-your-muscle

Learning concepts and sample practice code - C#, MVC, SQL etc..
2 stars 0 forks source link

Diff between DTO (Data Transfer Object)and POCO (Plane old clr Objects) objects #28

Closed RajasekharwhY closed 5 years ago

RajasekharwhY commented 5 years ago

Diff between DTO (Data Transfer Object)and POCO (Plane old clr Objects) objects: DTO -> (Data transfer object (DTO), formerly known as value objects or VO, is a design pattern), used to transfer data between software application subsystems.

POCO -> is an abbreviation for Plain Old CLR Objects. This class does not inherit functionality of any specific framework or technology. It is a simple public class and just contains properties and methods. These methods do not implement persistent logic such as saving and retrieving data from the database. This is the reason why we call these classes as Persistence Ignorant classes. POCO classes are persistent ignorant which means that they are not aware of where and how to save data. These classes will make use of an available persistent infrastructure. These classes implement only the domain business logic of the application. You may be wondering by now, where should we write persistent methods. The answer is repositories. If we start using these classes with repositories, we can appreciate the power of Plain Old CLR Objects.

Briefly, the advantages are:

We can always replace the data access technology from EF with any other data access technology. We need not change or rewrite the Business Layer and Presentation Layer. By doing this, we reduce the dependency between layers.

Some programmers prefer to use DTOs (Data Transfer Objects) with these classes to pass data between layers. They feel that when POCOs are used to pass information between layers, they become heavy which is unnecessary. So, they use DTOs which are also classes. The main difference between DTOs and POCOs is that DTOs do not contain any methods