liveBook · Manning

Anticorruption layer

As explained in Unit Testing Principles, Practices, and Patterns

An architectural boundary that isolates a domain model from the concepts and interfaces of an external system or model.

An anticorruption layer is an adapter boundary between application code and an external system. It hides third-party complexity, exposes only needed capabilities, and expresses them in the project’s domain language. section 9.2

Use the boundary to:

  • Mock the project-owned adapter rather than an external library interface whose behavior may be misunderstood or change during upgrades. section 9.2
  • Restrict upgrade ripple effects to the adapter instead of spreading third-party changes across the codebase. section 9.2
  • Avoid wrappers for in-process dependencies unless the added abstraction provides worthwhile value. section 9.2

Message-bus adapter

An IBus interface in a CRM application can wrap a message-bus library, exposing application-specific operations while allowing tests to mock IBus and verify messages without coupling to the library’s interface. section 9.2

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines adapters that hide library complexity, expose needed features in domain language, and limit upgrade ripple effects to one class.
Examples
Uses an IBus wrapper around a message-bus library and verifies an email-change message through the project-owned interface.
What it assumes
Assumes familiarity with external libraries and mocking, while distinguishing unmanaged dependencies from in-process dependencies.
What you can do after
Apply it by wrapping an external library, exposing needed domain operations, and mocking the wrapper in tests.
How it connects
Connects adapters with mocking, unmanaged dependencies, third-party libraries, domain language, and message buses.

Also explained in

Compare how 3 books explain anticorruption layer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.