3. PROBLEM
• Client should works with specific interface (Interface A), but
the logic is under another interface (Interface B) for some
reason (e.g. external library).
Interface A Syste
m
Interface B
Syste
m
4. ADAPTER PATTERN
• Adapter pattern is one of the structural design patterns.
• It works as a bridge between two incompatible interfaces.
• This pattern involves a single class which is responsible to join
functionalities of independent or incompatible interfaces.
• Adapter doesn’t add new behavior to our interface.
5. SOLUTION
• We create adapter class that implements our Interface A and
has a reference to Interface B as a member.
• In the implemented methods from Interface A, we call Interface
B methods from its reference.
Interface B
Adapter
(implements
Interface A)
Syste
m
9. PROS. VS CONS.
• The overall complexity of the
code increases because you
need to add a set of new
interfaces and classes.
• Single Responsibility
Principle: separate data
conversion code from the
primary business logic of the
program.
• Open/Closed Principle: add
new types of adapters into
the program without
modifying the existing client
code.
Editor's Notes
The Single Responsibility Principle — Classes should have a single responsibility and thus only a single reason to change.
Open/Closed Principle — Classes and other entities should be open for extension but closed for modification. ------------ because they work with the adapters through the client interface