Understanding
π‘ DTO (Data Transfer Object)π¦ Entityπ¦ VO (Value Object)π¦ DAO (Data Access Object)can be critical as due to their similarities, these objects are interchangeably applied in the actual industry source codes.
Hence, in the following sections, all these objects will be discussed.
π‘ DTO (Data Transfer Object)is anobjectin which it is often used to transferdataacross thelayers.π
Layersincludecontroller,services,repositories,filters,facades, andetc.
DTO is a pure data object that only contains data fields and getters() and setters() hence, DTO holds no business logic.
DTO, however, evolved over time such that its subtype DTO, the business objects contains business-related logics. A good example could be the toEntity() method, where it transforms itself to the related Entity object or potentially other methods.
π¦
Entityis anobjectthat is mapped to a table in a realdatabase.
Entity can be identified by its id. In the Java Persistence packages, entity can be defined by the @Entity annotation while the id can defined by the @Id annotation.
Entity can contain business logic inside as well.
π¦
VO (Value Object)is anobjectthat represents thedatawithin theobject.
VO can contain any business logic, and by its nature, followed by the final keyword ensures the immutability of the data.
VO also assumes any other VO with the same data fields as equal. Hence, equals() and hashCode() methods have to be @Overridden to define and instantiate VO.
π¦
DAO(Data Access Object) is anobjectwhere it is capable ofsearchingandmanipulating datain thedatabasesviaDB connection.
DAO is considered to have been deprecated as DAO contains two varying concerns within a single class, Database connection logics and the Entity related logics and fields.
Hence, DAO's presence violates the SRP from the SOLID principles.