Request를 VO가 아닌 DTO로 구현하는 이유

sith-call.dev·2023년 4월 18일
0

WEB

목록 보기
5/6

Chat GPT

which way is better between implement request as dto and as vo?

Both DTO (Data Transfer Object) and VO (Value Object) are commonly used to transfer data between layers or modules of an application. However, they have slightly different purposes and use cases.A DTO is typically used to transfer data between layers of an application or between different applications, and it is often used in a distributed architecture where data needs to be serialized and deserialized. DTOs are usually designed to be a simple container for data, and they often contain only data without any business logic or behavior.

On the other hand, a VO is a domain object that represents a value or a concept in the business domain. A VO may have behavior or business logic associated with it, and it is usually used within a single module or layer of an application.

In terms of which approach is better, it depends on the specific use case and requirements of your application. If you are transferring data between different layers or modules of an application or between different applications, a DTO is usually a better choice because it is designed for this purpose and is more lightweight. If you are working within a single module or layer of an application and need to represent a value or concept in the business domain, a VO may be a better choice because it can encapsulate behavior and business logic.
In general, it's a good practice to use DTOs for data transfer and VOs for representing domain concepts, but ultimately the choice depends on the specific needs of your application.

DTO

  • Layer 간의 데이터를 전송할 때 사용하는 객체

VO

  • 도메인에서 한 개 또는 그 이상의 속성들을 묶어서 특정 값을 나타내는 객체

정리

즉, VO는 도메인 영역에 있는 값(엔티티)를 나타내거나 엔티티의 속성들로 이뤄진 값을 나타내는 용도로 사용한다.
그렇기 때문에 애초에 그 용도가 Software Architecture를 구성하는 Layer 간의 데이터 전송과는 아무런 관련이 없다.
따라서 Request는 DTO로 구현한다.

참고문서

  1. https://tecoble.techcourse.co.kr/post/2020-06-11-value-object/

2. https://jaehoney.tistory.com/287

profile
lim (time -> inf) life(time) = LOVE

0개의 댓글