DEV Community

LFC
LFC

Posted on • Edited on

Quick approach: Anti-corruption layer pattern

The anti-corruption layer pattern implements a facade or adapter between different systems with different semantics. The main purpose is to translate the request from one system to another, trying to reduce dependencies and limitations.

"Create an isolating layer to provide clients with functionality in terms of their own domain model. The layer talks to the other system through its existing interface, requiring little or no modification to the other system. Internally the layer translates in both directions as necessary between the two models"
Eric Evansโ€™s Domain Driven Design book

Context

Several companies dedicate their efforts to solving specific problems under specific mechanisms, technologies and architectures, forgetting a potential unification or communication of those systems in the future.

Many of these scenarios are present when trying to interface a new or recent system with legacy components, causing compatibility issues. In these cases, the priority must be to respect the restrictions of the system and not include bad practices in our code in order to force communication between those involved.

An ally to solve this problem is to implement an anti-corruption layer, which serves as an adapter and translator between the requests that the systems or subsystems involved make.

Image description

When to use?

If you do not have homogeneous systems, you can use this pattern in order to avoid mixing protocols and communication mechanisms between different architectures and subsystems.

Advantages

  • A standard interface to expose functionality.
  • Evolve implementations without sacrificing compatibility or efficiency.
  • Discovering services may be easier through a middle layer.
  • Centralized error handling in the middle layer.
  • Move and unify communication, monitoring, security, and interoperability responsibilities to a layer that does not interfere with legacy or new systems.

Top comments (0)