Adaptor Pattern
Purpose
The term adaptor comes from the general lexicon.
An adapter (also known as a wrapper) translates one interface for a class into a compatible interface. An adapter allows classes to work together that normally could not because of incompatible interfaces, by providing its interface to clients while using the original interface. The adapter translates calls to its interface into calls to the original interface. The adapter is also used to transform data into appropriate forms. For instance, if multiple boolean values are stored as a single integer but your consumer requires a 'true'/'false', the adapter would be responsible for extracting the appropriate values from the integer value.
Structure
See Wikipedia entry.
Related Patterns
- Bridge
- Has a structure similar to an object adapter.
- Bridge separates an interface from its implementation so that they can change easily and independently. Both the interface and the implementation presumably are under the control of the same designer.
- An adaptor is used to change the interface of an existing class that the designer of the adaptor presumably has no control over (e.g., a Java.util class).
- Facade
- Is a bridge between clients and a system of classes.
- A Bridge is a degenerate case of a Facade.
- Mediator
- Is a bidirectional Facade, mediating between 2 subsystems.
- Mediator can centralize code (not just interface) that combines the functionality of subsystem method[s].
- Facade typically facilitates communication from a client to a subsystem.
- A Facade thus is a degenerate form of a Mediator.
- Although Mediator is the most general design pattern, use a Mediator only when restricted versions do not suffice: Simpler is better.