πŸ›³οΈ DTO, Entity, VO, DAO

GunhoΒ·2024λ…„ 12μ›” 25일
0

Object Oriented Programming (OOP) & Java

λͺ©λ‘ 보기
26/29

πŸ–οΈ Overview

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)

🐑 DTO (Data Transfer Object) is an object in which it is often used to transfer data across the layers.

🌊 Layers include controller, services, repositories, filters, facades, and etc.

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.


🦐 Entity

🦐 Entity is an object that is mapped to a table in a real database.

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)

πŸ¦€ VO (Value Object) is an object that represents the data within the object.

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)

πŸ¦‘ DAO (Data Access Object) is an object where it is capable of searching and manipulating data in the databases via DB 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.


πŸ“š References

μš°μ•„ν•œ ν…Œν¬ μ½”μŠ€
ν† λΉ„μ˜ μŠ€ν”„λ§

profile
Hello

0개의 λŒ“κΈ€