0% found this document useful (0 votes)
84 views

Adapter Presentation

The Adapter pattern allows classes with incompatible interfaces to work together by wrapping its interface with a new class. This converts the interface of an existing class into a compatible interface that clients expect. The pattern involves a target interface that clients use, an existing adaptee class with an incompatible interface, and an adapter class that acts as a wrapper by implementing the target interface and delegating work to adaptee objects.

Uploaded by

Arafat Turjoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Adapter Presentation

The Adapter pattern allows classes with incompatible interfaces to work together by wrapping its interface with a new class. This converts the interface of an existing class into a compatible interface that clients expect. The pattern involves a target interface that clients use, an existing adaptee class with an incompatible interface, and an adapter class that acts as a wrapper by implementing the target interface and delegating work to adaptee objects.

Uploaded by

Arafat Turjoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Adapter Pattern

Adapter Pattern

Intent


A structural design pattern that convert the interface of a
class into another interface clients expect. Adapter lets
classes work together that couldn't otherwise because of
incompatible interfaces

Wrap an existing class with a new interface.
Adapter Pattern

Problem
Let we have a media player which can play audio for some
reasons we want our media player can also play MP4 and
VLC files


Solution

We may write new code

We may use existing code that developed by others (3rd
party) or we developed before
Adapter Pattern

There is a catch

Our previous code is not compatible with our current project

Others code is also not compatible with our project


Solution?

We can change our/others code

We can use an adapter which can
convert the incompatible code
into our desired format
Adapter Pattern

Applicability

Use the Adapter class when you want to use some existing
class, but its interface isn’t compatible with the rest of your
code.

Use the adapter class for creating a reusable class that
cooperates with unrelated or unforeseen classes, that is,
classes that don't necessarily have compatible interfaces

Use the adapter pattern when you need to use several
existing subclasses, but it's impractical to adapt their interface
by subclassing every one. An object adapter can adapt the
interface of its parent class
Adapter Pattern
(How to do?)

Multiple Inheritance
Adapter Pattern
(How to do?)

Composition
Adapter Pattern

Participants

Target

defines the domain-specific interface that Client uses.

Client

collaborates with objects conforming to the Target interface.

Adaptee

defines an existing interface that needs adapting.
• Adapter

adapts the interface of Adaptee to the Target interface.
Adapter Pattern
(Implementation)
Adapter Pattern
(Implementation: Client )
Adapter Pattern
(Implementation: Target Class)
Adapter Pattern
(Implementation: Adapter Class)
Adapter Pattern
(Implementation: Adaptee Class)
THANK YOU

You might also like