Beginners 'DTO (Data Transfer Object) vs View Model vs Domain Model vs Entity Model.

Posted on January 10, 2023
.NET Corebeginnersdotnetarchitecturepattern

Many naming conventions are used in the web development space, and most terminologies confused junior developers. Here is the basic difference between DTO (Data Transfer Object) vs View Model vs Domain Model vs Entity Model. 

Let's understand by definition

Domain Model - A domain model contains clusters of different data entities and processes that can control a significant area of functionality, such as order fulfillment or inventory. A more fine-grained DDD unit is the aggregate, which describes a cluster or group of entities and behaviors that can be treated as a cohesive unit.

DTO (Data Transfer Object) - DTO stands for “Data Transfer Object”, and implies that it is a serializable entity that is to be transferred between systems. This immediately gives valuable information to the developer. It tells the developer to be careful removing elements from this object, as an external system may depend on the field. Even if the code compiles, run time errors or erroneous behavior may occur at run time because of the transfer of data across the wire.

Another benefit of DTOs is it allows modifications to be done on the domain model (in domain-driven development) without impacting external systems. 

View Model - View Models are similar to DTOs in that are made to go over the wire (as in the case if you are using a Javascript framework or library). They are another construct that is derived from the domain model but has been modified to fit the requirements of an external system. In the case of View models, the external system is an internal subsystem responsible for displaying the data in a UI.

Entity Model - An Entity Model represents a specific object from the database and must have unique entity keys. Also most of the time these models are related to each other objects. The entities Model mainly interacts with the database.

Let's understand my experience with high-level diagram

high-level diagram

Let's say the user requests from the browser then requests will go to the database then, the Database query response will map the data in form of an Entity Model and next, Entity Model will be transformed into the domain model. Now domain model can be transformed to DTO or view model based on respective factors. DTO is transferred between systems or within the communication of microservices and View Model mainly for displaying data in a UI by transforming data from the domain model

Thanks for reading!


Posted on January 10, 2023

Anonymous User

September 7, 2023

?

Anonymous User

September 7, 2023

Anonymous User

September 7, 2023

Anonymous User

September 7, 2023

Anonymous User

September 7, 2023

Anonymous User

September 7, 2023

Profile Picture

Arun Yadav

Software Architect | Full Stack Web Developer | Cloud/Containers

Subscribe
to our Newsletter

Signup for our weekly newsletter to get the latest news, articles and update in your inbox.

More Related Articles