SlideShare a Scribd company logo
Adapter-1
© Gunnar Gotshalks
Adapter Pattern – Structural
• Intent
» Convert the interface of a class into another
interface that the client expects.
» Lets classes work together that couldn't otherwise
Adapter-2
© Gunnar Gotshalks
Class Adapter –!Motivation
• EDITOR expects a SHAPE
• TEXT_VIEW is not a SHAPE
• TEXT_SHAPE is a SHAPE
Reuse TEXT_VIEW in the context of a SHAPE
TEXT_VIEW
SHAPE
TEXT_SHAPE
FIGURE_SHAPE
EDITOR
Adapter-3
© Gunnar Gotshalks
Object Adapter –!Motivation
• EDITOR expects a SHAPE
• TEXT_VIEW is not a SHAPE
• TEXT_SHAPE is a SHAPE
Reuse subclasses of TEXT_VIEW in the context of
a SHAPE
SHAPE
TEXT_SHAPE
FIGURE_SHAPE
EDITOR
TEXT_VIEW
TEXT_A TEXT_B
Adapter-4
© Gunnar Gotshalks
Adapter – Applicability
• Use an existing class when its interface does not
match the one you need
• Create a class that cooperates with unrelated or
unforeseen classes with incompatible interfaces
• Object Adapter Only
Need to use several existing subclasses, but it is
impractical to adapt by sub-classing each one of
them
Object adapter adapts the interface of the parent
class
Adapter-5
© Gunnar Gotshalks
Adapter – Participants
• TARGET
Application interface
• Client
Target user
• Adaptee
Interface that needs
adapting
• Adapter
– alternative name wrapper
Provides functionality not
provided by the adaptee
ADAPTER
ADAPTEE
TARGET
CLIENT
Either relationship (only 1 of
them for an ADAPTER)
is_a – class adapter
has_a – object adapter
Adapter-6
© Gunnar Gotshalks
Object Adapter – Scenario
ADAPTER
ADAPTEE
TARGET
CLIENT
adaptee : ADAPTEE
method_in_target
Scenario – collaboration
1 Client does
target.method_in_target
2 Adapter does
adaptee.method_in_adaptee
(note polymorphism)
CLIENT
TARGET
ADAPTEE
1
2
Adapter-7
© Gunnar Gotshalks
Adapter Object – Pseudocode
class ADAPTER
feature
adaptee : ADAPTEE
...
method_in_target is
pre_actions
adaptee . method_in_adaptee
post_actions
end
end
end
class ADAPTEE
feature
method_in_adaptee is ... end
end
end
Adapter-8
© Gunnar Gotshalks
Adapter Object –!Stack Implementation
• The Adapter pattern used where stack operations are
calls to "equivalent" sequence operations
Sequence container;
• Push – Uses the Sequence putHead
public void push(final Object obj) {
container.putHead(obj); }
• Pop –!Use the Sequence takeHead
public Object pop() {
return container.takeHead(); }
Adapter-9
© Gunnar Gotshalks
Adapter – Consequences
• There are tradeoffs –!a class adapter – inheritance
» adapts Adaptee to Target by committing to
concrete Adapter class
Class adapter is not useful when we want to
adapt a class and all its subclasses
» Lets Adapter override some of Adaptee's
behaviour
Adapter is a subclass of Adaptee
» Introduces only one object
No additional pointer indirection is needed to
get to adaptee
Adapter-10
© Gunnar Gotshalks
Adapter – Consequences – 2
• There are tradeoffs – an object adapter – uses
» One Adapter can work with many Adaptees
> Adaptee and all its subclasses
> Can add functionality to all Adaptees at once
» Makes it harder to override Adaptee behaviour
Requires making ADAPTER refer to the
subclass rather than the ADAPTEE itself
Or
Subclassing ADAPTER for each ADAPTEE
subclass
Adapter-11
© Gunnar Gotshalks
Adapter – Related Patterns
• Bridge is similar to object Adapter but Bridge is
meant to separate interface from implementation so
they can vary independently, while Adapter extends
the interface of an existing object
• Decorator is more transparent than Adapter, so
Decorator supports recursive composition, while
Adapter doesn't
• Proxy defines a representative for another object and
does not change its interface

More Related Content

Similar to software Structural design pattern Adapter (20)

PDF
Design Patterns
Srikrishnan Suresh
 
PPT
Ch06.ppt
DeekshithaReddy63
 
PPTX
Design patterns
Luis Goldster
 
PPTX
Design p atterns
Amr Abd El Latief
 
PDF
Software and architecture design pattern
sanjanakorawar
 
PDF
Hadoop Cluster on Docker Containers
pranav_joshi
 
PPTX
Java 8 Features
Leninkumar Koppoju
 
PPTX
Adapter Pattern
Monjurul Habib
 
PPTX
Adapter Design Pattern
Shahriar Iqbal Chowdhury
 
PPTX
Domain Driven Design
Khrystyna Makar
 
PPTX
Design patterns
Akhilesh Gupta
 
PDF
Working With Concurrency In Java 8
Heartin Jacob
 
PDF
Structure Facade deign pattern model fact
mdimberu
 
PPTX
Angular TS(typescript)
Ivan Stepić
 
PPTX
FRONTEND BOOTCAMP Session 2.pptx
Ehtesham46
 
PPTX
31 days Refactoring
Ahasanul Kalam Akib
 
PPT
Stoop 440-adaptor
The World of Smalltalk
 
PPTX
Segue to design patterns
Rahul Singh
 
PPTX
ITea&Coffee: React best practices
Agata Piórkowska
 
PPTX
Operationalizing YARN based Hadoop Clusters in the Cloud
DataWorks Summit/Hadoop Summit
 
Design Patterns
Srikrishnan Suresh
 
Design patterns
Luis Goldster
 
Design p atterns
Amr Abd El Latief
 
Software and architecture design pattern
sanjanakorawar
 
Hadoop Cluster on Docker Containers
pranav_joshi
 
Java 8 Features
Leninkumar Koppoju
 
Adapter Pattern
Monjurul Habib
 
Adapter Design Pattern
Shahriar Iqbal Chowdhury
 
Domain Driven Design
Khrystyna Makar
 
Design patterns
Akhilesh Gupta
 
Working With Concurrency In Java 8
Heartin Jacob
 
Structure Facade deign pattern model fact
mdimberu
 
Angular TS(typescript)
Ivan Stepić
 
FRONTEND BOOTCAMP Session 2.pptx
Ehtesham46
 
31 days Refactoring
Ahasanul Kalam Akib
 
Stoop 440-adaptor
The World of Smalltalk
 
Segue to design patterns
Rahul Singh
 
ITea&Coffee: React best practices
Agata Piórkowska
 
Operationalizing YARN based Hadoop Clusters in the Cloud
DataWorks Summit/Hadoop Summit
 

Recently uploaded (20)

PDF
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
PPTX
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
PDF
NPD Software -Omnex systems
omnex systems
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Show Which Projects Support Your Strategy and Deliver Results with OnePlan df
OnePlan Solutions
 
PPTX
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
Best Web development company in india 2025
Greenusys
 
PDF
Code and No-Code Journeys: The Maintenance Shortcut
Applitools
 
PDF
10 Salesforce Consulting Companies in Sydney.pdf
DianApps Technologies
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
PDF
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
intro_to_cpp_namespace_robotics_corner.pdf
MohamedSaied877003
 
iaas vs paas vs saas :choosing your cloud strategy
CloudlayaTechnology
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Latest Capcut Pro 5.9.0 Crack Version For PC {Fully 2025
utfefguu
 
NPD Software -Omnex systems
omnex systems
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Show Which Projects Support Your Strategy and Deliver Results with OnePlan df
OnePlan Solutions
 
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Best Web development company in india 2025
Greenusys
 
Code and No-Code Journeys: The Maintenance Shortcut
Applitools
 
10 Salesforce Consulting Companies in Sydney.pdf
DianApps Technologies
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
Ad

software Structural design pattern Adapter

  • 1. Adapter-1 © Gunnar Gotshalks Adapter Pattern – Structural • Intent » Convert the interface of a class into another interface that the client expects. » Lets classes work together that couldn't otherwise
  • 2. Adapter-2 © Gunnar Gotshalks Class Adapter –!Motivation • EDITOR expects a SHAPE • TEXT_VIEW is not a SHAPE • TEXT_SHAPE is a SHAPE Reuse TEXT_VIEW in the context of a SHAPE TEXT_VIEW SHAPE TEXT_SHAPE FIGURE_SHAPE EDITOR
  • 3. Adapter-3 © Gunnar Gotshalks Object Adapter –!Motivation • EDITOR expects a SHAPE • TEXT_VIEW is not a SHAPE • TEXT_SHAPE is a SHAPE Reuse subclasses of TEXT_VIEW in the context of a SHAPE SHAPE TEXT_SHAPE FIGURE_SHAPE EDITOR TEXT_VIEW TEXT_A TEXT_B
  • 4. Adapter-4 © Gunnar Gotshalks Adapter – Applicability • Use an existing class when its interface does not match the one you need • Create a class that cooperates with unrelated or unforeseen classes with incompatible interfaces • Object Adapter Only Need to use several existing subclasses, but it is impractical to adapt by sub-classing each one of them Object adapter adapts the interface of the parent class
  • 5. Adapter-5 © Gunnar Gotshalks Adapter – Participants • TARGET Application interface • Client Target user • Adaptee Interface that needs adapting • Adapter – alternative name wrapper Provides functionality not provided by the adaptee ADAPTER ADAPTEE TARGET CLIENT Either relationship (only 1 of them for an ADAPTER) is_a – class adapter has_a – object adapter
  • 6. Adapter-6 © Gunnar Gotshalks Object Adapter – Scenario ADAPTER ADAPTEE TARGET CLIENT adaptee : ADAPTEE method_in_target Scenario – collaboration 1 Client does target.method_in_target 2 Adapter does adaptee.method_in_adaptee (note polymorphism) CLIENT TARGET ADAPTEE 1 2
  • 7. Adapter-7 © Gunnar Gotshalks Adapter Object – Pseudocode class ADAPTER feature adaptee : ADAPTEE ... method_in_target is pre_actions adaptee . method_in_adaptee post_actions end end end class ADAPTEE feature method_in_adaptee is ... end end end
  • 8. Adapter-8 © Gunnar Gotshalks Adapter Object –!Stack Implementation • The Adapter pattern used where stack operations are calls to "equivalent" sequence operations Sequence container; • Push – Uses the Sequence putHead public void push(final Object obj) { container.putHead(obj); } • Pop –!Use the Sequence takeHead public Object pop() { return container.takeHead(); }
  • 9. Adapter-9 © Gunnar Gotshalks Adapter – Consequences • There are tradeoffs –!a class adapter – inheritance » adapts Adaptee to Target by committing to concrete Adapter class Class adapter is not useful when we want to adapt a class and all its subclasses » Lets Adapter override some of Adaptee's behaviour Adapter is a subclass of Adaptee » Introduces only one object No additional pointer indirection is needed to get to adaptee
  • 10. Adapter-10 © Gunnar Gotshalks Adapter – Consequences – 2 • There are tradeoffs – an object adapter – uses » One Adapter can work with many Adaptees > Adaptee and all its subclasses > Can add functionality to all Adaptees at once » Makes it harder to override Adaptee behaviour Requires making ADAPTER refer to the subclass rather than the ADAPTEE itself Or Subclassing ADAPTER for each ADAPTEE subclass
  • 11. Adapter-11 © Gunnar Gotshalks Adapter – Related Patterns • Bridge is similar to object Adapter but Bridge is meant to separate interface from implementation so they can vary independently, while Adapter extends the interface of an existing object • Decorator is more transparent than Adapter, so Decorator supports recursive composition, while Adapter doesn't • Proxy defines a representative for another object and does not change its interface