Intro
- 도메인 영역의 주요 구성요소
- 엔티티
- 고유 식별자를 갖는 객체
- 도메인 고유 개념 표현
- 밸류
- 식별자를 갖지 않는 객체
- 개념적인 하나의 값을 표현
- 엔티티 속성, 다른 밸류 타입 속성으로 사용 가능
- 애그리거트
- 연관된 엔티티와 밸류 객체를 개념적으로 하나로 묶은 것
- Order, OrderLine, Ordrerer 를 주문 애그리거트로 묶을 수 있음
- 리포지터리
- 도메인 서비스
2.4.1 엔티티와 밸류
- 개발 초년 시절, DB 테이블의 엔티티와 도메인 모델의 엔티티를 구분하지 못해 동일하게 만듦
- 도메인 모델 엔티티는 데이터와 도메인 기능을 함께 제공
- 도메인 모델 엔티티는 데이터가 개념적으로 하나인 경우 밸류 타입을 이용해서 표현 가능
- 밸류타입의 교체로 개념적으로 한꺼번에 업데이트 해야하는 개념임을 나타낼 수 있음
2.4.2 애그리거트 (Aggregate)
- 엔티티와 밸류 개수가 많아질수록 모델은 점덤 더 복잡해진다
- 이때 개별 구조에 집중하는 상황이 발생.
- 상위 수준에 모델을 관리하지 않고 개별에 집중하다 보면, 큰 수준에서 모델을 이해못해 모델을 큰 그림의 모델 관리를 할 수 없음
- 도메인 모델에서 전체 구조를 이해하는데 도움이 되는 것에 애그리거트(Aggregate)
- 에그리게이트는 동사형 표현, 명사 발음은 애그리거트
- 애그리거트 구성
- 군집에 속한 객체를 관리하는 루트 엔티티 존재
- 루트 엔티티는 애그리거트에 속해있는 엔티티와 밸류 객체를 이용해 애그리거트가 구현해야할 기능을 제공
2.4.3 리포지터리 (Repository)
- 물리적인 저장소에 도메인 객체를 보관해야하는데 이때 사용하는 도메인 모델이 리포지터리
- 엔티티나 밸류는 요규사항에 의해 도출되는 도메인 모델
- 리포지터리는 구현을 위한 도메인 모델