Glossary · Automation software engineering and architecture
Adapter pattern
Also known as: Adapter, Wrapper pattern
German: Adaptermuster
In software engineering, the adapter pattern is a structural design pattern that converts the interface of an existing component into another interface that clients expect, so components with incompatible interfaces can work together without changing either of them.
- Software engineering
In one sentence
The adapter pattern converts one component's interface into the interface a client expects, so incompatible parts can work together.
Example
An adapter class maps a vendor-specific drive library to the machine's generic 'Axis' interface, so the motion sequence code stays unchanged when the drive supplier changes.
How it applies
- Engineering: Adapters are common at the edges of automation software: wrapping a device driver, a legacy PLC library or a third-party API behind the interface used in the rest of the application.
- Maintenance: When a component is replaced, only the adapter has to change. Keep adapters thin so that they translate data and calls without adding business logic.
- Documentation: Record which external interface each adapter wraps, including its version, units and value ranges, and how values are converted. Unit or scaling conversions inside adapters are a frequent source of errors and should be visible in the interface documentation.
Adapter vs. facade
An adapter makes an existing interface match a different, expected interface. A Facade pattern defines a new, simpler interface to a whole subsystem. Adapters solve compatibility problems; facades reduce complexity.
In Hexagonal architecture, adapters connect the application core to the outside world through ports.