The Anti-Corruption Layer (ACL) is used to prevent "leakage" of unwanted logic, models, or data between integrated systems. This pattern implements an intermediary layer of translators, adapters, and facades to isolate one domain model from another.
For example, when integrating an old accounting system with a new e-commerce platform, the ACL will allow for data format conversion, validation, and correct handling of the business rules on both sides.
class LegacyUserDTO: def __init__(self, legacy_id, fname, lname): self.legacy_id = legacy_id self.fname = fname self.lname = lname class ModernUser: def __init__(self, id, first_name, last_name): self.id = id self.first_name = first_name self.last_name = last_name def acl_translate(legacy_user): return ModernUser( id=legacy_user.legacy_id, first_name=legacy_user.fname, last_name=legacy_user.lname )
Can serialization or ORM be used instead of the anti-corruption layer?
Serialization and ORM facilitate data transfer and storage but do not protect the domain model from external influences. Only the ACL provides isolation of logic and compliance with the business rules of both systems.
In what cases is the ACL not needed?
The ACL is generally not needed if both systems have identical or agreed-upon models and are controlled by the same team. However, in practice, even minor differences can lead to problems without the ACL.
What happens if integration is done directly without the ACL?
There is a high risk that changes in the external system will negatively impact the business logic of the main system or cause bugs.