Adapter
Implements the Port to perform a job using one Supplier.
Details
The Adapter adapts the Port’s simplified perspective of the job to a single Supplier’s complex perspective of that job. Because the Supplier needs to serve multiple consumers, it necessarily needs complexity that is not used by this one consumer. The Adapter encapsulates that unused complexity, while the Port exposes the complexity used by the Application.
The Adapter often starts as simple glue code, translating calls from Port to Supplier. However, it then quickly starts supplying data values that the Port doesn’t want to expose. Next it starts handling changes in Supplier behaviors. When the supplier changes and your Application’s needs don’t, the Adapter absorbs the change.
Adapters start small but can eventually get very large. This makes it important to unit test them even when they are small.
Implementation
The Adapter is usually implemented as:
- one or more classes that implement the interfaces from the Port,
- the usual client code for interacting with its Supplier, and
- glue code to translate between them.
The Adapter is tested using unit tests for the glue code. The Contract Tests serve as a set of Acceptance Platform tests to guide implementation.
Dependencies
The Adapter can see the Port that it implements and the API for the Supplier that it consumes. It trusts the Port (and the calls coming through it) but does not trust the Supplier.