Search code examples
javaspring-bootdto

List differences: DTO, VO, Entity, Domain, Model


Now I study about the Spring Boot that with JAVA platform.

A problem I faced is how can you tell the difference between DTO, VO, Entity, Domain, and Model.

Honestly it all look too similar to tell the difference.

I already checked some stackoverflow answers about "Difference between DTO and VO" and something like that.

However, I am still wondering how do they different each other in terms of developer with Spring Boot.


Solution

    • Entity - is a class with an ID. In the case of relational DB it's usually a class that's mapped to a DB table with some primary key.
    • DTO (Data Transfer Object) - is a class that maps well on what you're sending over the network. E.g. if you exchange JSON or XML data, it usually has fields just enough to fill those requests/responses. Note, that it may have fewer or more fields than Entity.
    • VO (Value Object) is a class-value. E.g. you could create class like Grams or Money - it will contain some primitives (e.g. some double value) and it's possible to compare Value Objects using these primitives. They don't have a database ID. They help replacing primitives with more object-oriented classes related to our particular domain.
    • Domain Model contains all Entities and Value Objects. And some other types of classes depending on the classification you use.

    In order to get acquainted with these you should read:

    • Enterprise Application Patterns by Fowler. Mentions Value Object and Domain Model.
    • Domain Driven Design by Eric Evans. Mentions Entity, Value Object and Domain Model.
    • And maybe get acquainted with Java EE design patterns. They mention DTO. But these are pretty badly written articles (if they are still even available on the internet). Confusingly, they also had Value Object which was defined very similarly to DTO, but no one uses that definition of VO.