mardi 5 septembre 2023

What's the difference between Anti-Corruption Layer and Adapters?

Even thought there was a good answer here: https://softwareengineering.stackexchange.com/questions/184464/what-is-an-anti-corruption-layer-and-how-is-it-used, the explanaition is still a bit confusing me. I do not see any huge differences between Anti-Corruption layer and Adapters and the only difference that I see is the difference in the definitions that Anti Corruption Layer is a kind of wrapper that allows you to isolate your domain from the corruption of someone else's domain. But in another article, the Anti Corruption Layer is generally acting as Adapter: https://medium.com/solutions-architecture-patterns/anti-corruption-layer-pattern-bd75e1f2be7f

Let's take an example. I have a library that allows me to query MongoDB from code, developed by the official MongoDB developers for my programming language. I also have a user domain model (let's name it User). The User has a unique UserID, which must match the ID in MongoDB. The library for MongoDB uses the primitive.ObjectID type for identifiers. Because I don't want to refer to the types for the database from the domain model, I create a separate type Identifier, which, in fact, is a regular string. Thus, in the domain model, UserID will be of type Identifier, and primitive.ObjectID itself will be converted to Identifier during mapping by conversion to a string. Question: in this case, is Identifier an anti-corruption layer? Do you have any examples that can most accurately show me the difference between the anti-corruption layer and the adapter pattern?

I have read the following articles: https://learn.microsoft.com/en-us/azure/architecture/patterns/anti-corruption-layer https://medium.com/solutions-architecture-patterns/anti-corruption-layer-pattern-bd75e1f2be7f https://softwareengineering.stackexchange.com/questions/184464/what-is-an-anti-corruption-layer-and-how-is-it-used but none of them I find useful.

Aucun commentaire:

Enregistrer un commentaire