SOLID & Design Patterns Interview Question #79
What is an Anti-Corruption Layer?
DDD Boundaries, Resilience, Caching & Practical ASP.NET Core Design Mid-Level Intermediate
Quick Interview Answer
An Anti-Corruption Layer protects one model from concepts and structures belonging to another system or bounded context. It translates external contracts into the language and types expected by the local domain.
Detailed Explanation
An Anti-Corruption Layer protects one model from concepts and structures belonging to another system or bounded context. It translates external contracts into the language and types expected by the local domain.
This is especially useful when integrating legacy systems or third-party APIs. Without the layer, external terminology and data structures can leak throughout the domain model and increase coupling.
Code Example
public class LegacyCustomerAdapter
{
public Customer ToDomain(LegacyCustomerDto dto)
{
return new Customer(
new CustomerId(dto.CustomerNo),
dto.DisplayName);
}
}