Introduction
This post gives a brief overview about the Adapter Pattern. The post is part of a series about software design patterns and their UML representations with the help of PlantUML.
The article aims at providing a very short description of the general idea of the pattern in the first part. This also involves a descriptive UML diagram. Then, the second part provides the PlantUML code for the diagram so that these posts can also be used as a source of design patterns in PlantUML syntax.
What is the Adapter Pattern?
The Adapter Pattern is a design patternthat allows the interface of an existing class to be used as another interface.
The Adapter design pattern solves problems like:
- How can a class be reused that does not have an interface that a client requires?
- How can classes that have incompatible interfaces work together?
- How can an alternative interface be provided for a class?
Often an (already existing) class can’t be reused only because its interface doesn’t conform to the - interface clients require.
The Adapter design pattern describes how to solve such problems:
- Define a separate Adapter class that converts the (incompatible) interface of a class (Adaptee) into another interface (Target) clients require.
- Work through an Adapter to work with (reuse) classes that do not have the required interface.
The key idea in this pattern is to work through a separate Adapter that adapts the interface of an (already existing) class without changing it. Clients don’t know whether they work with a Target class directly or through an Adapter with a class that does not have the Target interface.
UML Diagram
The following diagram shows the Adapter Pattern in UML notation. It is based on the corresponding chapter in the book “Head First Design Patterns“:
You can click on the diagram to open it online in Pladitor.
Diagram Sources
Here are the diagram sources:
|
|