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

Structural Design Pattern (Adapter) : Prepared By: Husnain Ilyas Butt BITF16M512 Qamer Abbas BITF16M513

The Adapter pattern allows classes with incompatible interfaces to work together by converting the interface of one class into another interface clients expect. It works by having an Adapter class work as a bridge between the interface the client expects and the one provided by the Adaptee class. There are two common implementations of the Adapter pattern - class adapters work by subclassing the Adaptee class, while object adapters compose or contain the Adaptee class. The pattern allows classes to work together that otherwise could not due to incompatible interfaces.

Uploaded by

Shoaib Butt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Structural Design Pattern (Adapter) : Prepared By: Husnain Ilyas Butt BITF16M512 Qamer Abbas BITF16M513

The Adapter pattern allows classes with incompatible interfaces to work together by converting the interface of one class into another interface clients expect. It works by having an Adapter class work as a bridge between the interface the client expects and the one provided by the Adaptee class. There are two common implementations of the Adapter pattern - class adapters work by subclassing the Adaptee class, while object adapters compose or contain the Adaptee class. The pattern allows classes to work together that otherwise could not due to incompatible interfaces.

Uploaded by

Shoaib Butt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Structural Design

Pattern
(ADAPTER)
Prepared By:
Husnain Ilyas Butt BITF16M512
Qamer Abbas BITF16M513
Adapter Pattern

CONVERT THE INTERFACE OF A CLASS MAKE CLASSES WORK TOGETHER THAT


INTO ANOTHER INTERFACE CLIENTS COULDN'T OTHERWISE BECAUSE OF
EXPECT INCOMPATIBLE INTERFACES.
Example
(Plugs)
Participants

 Target : defines the domain-specific interface that


Client uses.
 Client : collaboration with objects conforming to
the Target interface
 Adaptee : defines an existing interface that needs
adapting.
 Adapter : adapts the interface of Adaptec to the
Target interface
Structure

Multiple Inheritance Composition


Better Approach
(Example)
Desire Desire to use an existing class ,
interface doesn’t match

Applicability
Want to create a reusable
class that cooperates with
unrelated classes, don't
necessarily have compatible
Want
interfaces.

Need to use several existing


subclasses, but it's unpractical

Need to adapt their interface by sub-


classing every one . An object
adapter can adapt the interface
of its parent class
Consequences

A class adapter

 adapts Adaptee to Target by committing to a


concrete Adaptee class . As a consequence, a
class adapter won't work when we want to
adapt a class and all its subclasses.
 let s Adapter override some of Adaptee's
behavior , since Adapter is a subclass of
Adaptee.
 introduces only one object, and no additional
pointer indirection is needed to get to the
adaptee.
Consequences
(Continued)
An object adapter

 let s a single Adapter work with many


Adaptees —that is, the Adaptee itself and all
of its subclasses (if any). The Adapter can
also add functionality to al l Adaptees at
once.
 makes it harder to override Adaptee
behavior. It will require sub-classing Adaptee
and making Adapter refer to the subclass
rather than the Adaptee itself.
Implementation

Implementing Class Pluggable Adapter


Adapter
Using Abstract Relation
Using Delegate Objects
Parameterized Adapters
Sample Code
Sample Code
(Continued)
Sample Code
(Continued)
Sample Code
(Continued)
Related Patterns

BRIDGE DECORATOR PROXY


Thank You!

You might also like