안티 코럽션 레이어(ACL, Anti-Corruption Layer)는 서로 다른 도메인 모델 또는 레거시 시스템 간의 변환 계층이다. 에릭 에반스의 DDD에서 제안되었으며, 외부 시스템의 모델이 자신의 도메인을 "오염"시키는 것을 방지한다.
문제
외부 시스템의 용어와 모델이 다름:
외부: customer_no, acct_type, bal_amt
내부: userId, accountType, balance
직접 사용 시:
내부 코드가 외부 개념에 의존
→ 레거시 교체 시 전체 수정 필요
→ 도메인 모델 오염
구현
typescript
// 외부 레거시 시스템 모델 (변경 불가)
interface LegacyCustomer {
cust_id: string;
cust_nm: string;
acct_bal: number;
acct_tp_cd: '01'|'02'|'03'; // 01=체크, 02=저축, 03=투자
}
// 내부 도메인 모델
interface Customer {
id: string;
name: string;
balance: number;
accountType: 'checking'|'savings'|'investment';
}
// Anti-Corruption Layer (변환 책임)
class LegacyCustomerAdapter {
private readonly ACCOUNT_TYPE_MAP = {
'01': 'checking',
'02': 'savings',
'03': 'investment',
} as const;
translate(legacy: LegacyCustomer): Customer {
return {
id: legacy.cust_id,
name: legacy.cust_nm,
balance: legacy.acct_bal,
accountType: this.ACCOUNT_TYPE_MAP[legacy.acct_tp_cd],
};
}
}
// 내부 코드: LegacyCustomer를 전혀 모름
class CustomerService {
constructor(private acl: LegacyCustomerAdapter) {}
getCustomer(id: string): Customer {
const legacy = legacyApi.getCustomer(id);
return this.acl.translate(legacy);
}
}
DDD 컨텍스트 맵에서의 위치
Upstream ACL Downstream
(레거시 시스템) ──────────▶ (새 바운디드 컨텍스트)
컨텍스트 맵 패턴:
- Open Host Service: 업스트림이 공개 API 제공
- Conformist: 다운스트림이 업스트림 모델 그대로 수용
- ACL: 다운스트림이 자신의 모델을 보호하며 변환
관련 개념