Summary

Short practical note on implementing a DDD Anti-Corruption Layer (ACL) to isolate a domain model from external system details. The pattern wraps external service calls in a repository that translates between the external representation (XSD-generated types) and the internal domain model, concentrating all adaptation logic in one place.

關於實現 DDD 防腐層(ACL)的簡短實踐筆記,用於隔離領域模型免受外部系統細節影響。該模式將外部服務調用包裝在倉儲中,在外部表示(XSD 生成類型)和內部領域模型之間進行轉換。

Key Points

  • ACL creates “padding” between bounded contexts so they don’t leak into each other
  • Even for systems you control, a thin ACL restricts the blast radius of external changes
  • Implementation: Repository pattern variant — each external service gets its own repository
  • Mappers translate between XSD-generated types and internal domain objects
  • Service-layer-only data (infrastructure concerns) should not flow into the core domain

Insights

The ACL is one of the most underused DDD patterns in practice — developers often let external representations (protobuf, XSD, DB schemas) leak directly into domain objects, creating tight coupling that makes future changes painful. The mapper pattern (FooIdToXsdFooRequestMapper, XsdFooResponseToFooMapper) makes the translation boundary explicit and testable. Even if the external system is internal to the organization, the ACL provides value by documenting the integration contract.

Connections

Raw Excerpt

Remember, an ANTICORRUPTION LAYER is a means of linking two BOUNDED CONTEXTS. Ordinarily, we are thinking of a system created by someone else; we have incomplete understanding of the system and little control over it.