architectureddddomain-driven-design
Domain-Driven Design - 도메인 중심 설계
조회 0
DDD(Domain-Driven Design)는 비즈니스 도메인을 중심으로 소프트웨어를 설계하는 방법론입니다.
이 글에서는 DDD의 핵심 개념과 실무 적용 방법을 정리합니다.
1. 핵심 개념
- Entity: 고유 식별자를 가진 객체
- Value Object: 값으로 정의되는 불변 객체
- Aggregate: 관련 엔티티를 묶는 루트
- Repository: 영속성 추상화
- Domain Service: 도메인 로직을 담는 서비스
2. Entity 예시
class User {
constructor(
private id: UserId,
private name: string,
private email: Email
) {}
changeEmail(newEmail: Email): void {
if (this.email.equals(newEmail)) {
throw new Error("Same email");
}
this.email = newEmail;
}
}
3. Value Object 예시
class Email {
constructor(private value: string) {
if (!this.isValid(value)) {
throw new Error();
}
}
(: ): {
.(email);
}
(: ): {
. === other.;
}
}