Course contentsShow
← Software Engineering
Lesson 1286 of 1,93338. Layered and Modular ArchitectureFree lesson

Translating Between Contexts

Implementing anti-corruption layers and translators to prevent external models from polluting internal domain models.

Translating Between Contexts

You'll learn how to implement anti-corruption layers and translators to keep external models from contaminating your internal domain models.

Why Translation Matters

When two Bounded Contexts need to communicate, they often speak different languages—literally. Your e-commerce system's "Order" might have a shippingAddress field, while the warehouse system calls it deliveryLocation. More critically, the meaning behind concepts can differ. Simply exposing your internal domain model to external systems (or vice versa) creates coupling and allows foreign assumptions to pollute your carefully designed model.

The Anti-Corruption Layer

Think of this as a diplomatic translator between countries. Just as a translator converts not just words but cultural context, an anti-corruption layer converts external data structures into your domain's language and concepts—and back again.

This layer sits at the boundary between contexts. When data comes in from an external system, the translator:

  1. Receives the foreign model
  2. Validates and interprets it according to external rules
  3. Maps it to your internal domain model
  4. Ensures only valid, meaningful domain objects enter your system

When data goes out, the process reverses: your rich domain objects get transformed into whatever format the external system expects.

Implementation Strategy

Create explicit translator or adapter classes at context boundaries. Never let external DTOs leak into your domain logic. Never expose your internal entities directly to external consumers. The translation code is intentionally "boring"—it maps fields, converts types, and handles the impedance mismatch between models.

This protects your domain from changes in external systems and preserves the integrity of your Ubiquitous Language within your context.

Key Takeaway: Anti-corruption layers act as protective translators, converting between external and internal models to prevent foreign concepts from polluting your domain and creating unwanted coupling between Bounded Contexts.