Replies: 4 comments 1 reply
-
VO(Value Object)는 값을 나타내는 객체입니다. 예를 들어 Java에서 제공하는 String은 이에 해당합니다. String은 char 배열을 감싸는 객체로, 불변성과 동등성을 보장합니다. 반면에, 원시값 포장은 원시값을 감싸는 것을 의미합니다. 이는 VO와 유사하지만, 원시값만을 감싸며 불변성과 동등성을 보장할 필요는 없습니다. 값 객체와 원시값 포장을 사용하는 이유는 값의 생성, 유효성 검사 및 관련 로직을 객체 내부로 캡슐화하여 책임을 하나의 객체에 모을 수 있기 때문입니다. |
Beta Was this translation helpful? Give feedback.
-
가장 큰 차이는 캡슐화입니다. 원시값 포장의 경우, primitive type을 객체로 래핑해야할 때 사용합니다. 반면 VO는 비즈니스 로직에서 사용되는 서로 연관있는 값을 캡슐화하기 위해 사용합니다. 이를 통해 유효성 검사 등의 로직을 객체 내부에 포함시킬 수 있습니다. |
Beta Was this translation helpful? Give feedback.
-
궁금한 점이 있는데 VO 객체를 할당한다면 동일성에 어긋나지않나요? Person p1 = new Person("John");
Person p2 = new Person("John");
// 동일성 (false)
System.out.println(p1 == p2);
// 동등성 (true)
System.out.println(p1.equals(p2)); |
Beta Was this translation helpful? Give feedback.
-
원시값 포장 - 원시값만 포장, 책임 분리 |
Beta Was this translation helpful? Give feedback.
-
.
Beta Was this translation helpful? Give feedback.
All reactions