Reputation: 21
Even thought there was a good answer here, the explanation 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.
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: 1, 2, 3 but none of them I find useful.
Upvotes: 1
Views: 1731
Reputation: 22829
As you can see, the flows are basically the same. You can think of the components like this:
Because these components are tend to be used together, sometimes all of these are smashed into a single component and it is usually named (badly) as an adapter. IMHO it is a better approach to have smaller, more focused components.
Upvotes: 6