SlideShare a Scribd company logo
1 of 13
Structural Design Patterns :
         Adapter




                   Manoj Kumar
                   Software Developer
                   manojksh9@gmail.com
Design Patterns

Design patterns are classified by two criteria:
Purpose and scope.

Creational: Concerns the process of object creation

Structural: Deals with the composition of classes or
objects

Behavioral: Characterizes the ways in which classes
or objects interact and distribute responsibility
Design Patterns




Purpose: Reflects what a pattern does
Scope: Specifies whether the pattern applies primarily to classes or to objec
Structural Design Patterns
                   Deals with the composition of classes or
                   objects
Structural patterns are concerned with how classes and
objects are composed to form larger structures.
Structural class patterns use inheritance to compose
interfaces or implementations.


Example:
Multiple inheritance mixes two or more classes into
one.


Class form of the Adapter pattern: In general, an
adapter makes one interface (the adaptee's) conform to
another, thereby providing a uniform abstraction of
different interfaces.
Structural Design Patterns :
Adapter
                    Deals with the composition of classes or
                    objects
Also Known As Wrapper

Convert the interface of a class into another interface
clients expect. Adapter lets classes work together that
couldn't otherwise because of incompatible interfaces.


What is an Adapter/Wrapper?

For Example: Shape + TextView = TextShape (Adapter)

Drawing editor: Draws lines/polygons, text; Pictures and
diagrams
Key abstraction: Graphical object (which has an editable shape and
can draw itself)
The interface for graphical objects: an abstract class “Shape”

The editor defines a subclass of Shape for each kind of graphical
object: a LineShape class for lines, a PolygonShape class for
polygons
Structural Design Patterns :
Adapter
                          Deals with the composition of classes or
                          objects
TextShape subclass: Display and edit, so considerably more difficult
to implement as complicated screen update and buffer management
are required
How to write this ‘TextShape’ subclass?

User interface toolkit (Already provide a sophisticated TextView class for
displaying and editing text)


A problem: Toolkit wasn't designed with Shape classes in mind. So we can't
use TextView and Shape objects interchangeably. How can existing and
unrelated classes like TextView work in an application that expects
classes with a different and incompatible interface?

Solution: A new class “TextShape” Adapts the TextView interface to
Shape's


                   An Adapter (Class version-by Inheriting
                           Object version-by composing)
Structural Design Patterns :
Adapter
              Deals with the composition of classes or
              objects




          Identify?? Class or Object
Structural Design Patterns :
Adapter
            Deals with the composition of classes or
            objects
Structural Design Patterns :
Adapter
                        Deals with the composition of classes or
                        objects
 Participants
 Target (Shape)
     defines the domain-specific interface that Client uses.
 Client (DrawingEditor)
     collaborates with objects conforming to the Target interface.
 Adaptee (TextView)
     defines an existing interface that needs adapting.
 Adapter (TextShape)
     adapts the interface of Adaptee to the Target interface.




 Collaborations
 Clients call operations on an Adapter instance. In turn, the adapter
 calls Adaptee operations that carry out the request.
Structural Design Patterns :
Adapter
                         Deals with the composition of classes or
                         objects
Consequences
Class and object adapters have different trade-offs.
A class adapter
adapts Adaptee to Target by committing to a concrete Adapter class.
As a consequence, a class adapter won't work when we want to adapt
a class and all its subclasses.
lets 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.

An object adapter
lets 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 all Adaptees at once.
makes it harder to override Adaptee behavior. It will require
subclassing Adaptee and making Adapter refer to the subclass rather
than the Adaptee itself.
Structural Design Patterns :
Adapter
                          Deals with the composition of classes or
                          objects
Applicability

You want to use an existing class, and its interface does not match
the one you need.

You want to create a reusable class that cooperates with unrelated
or unforeseen classes, that is, classes that don't necessarily have
compatible interfaces.

(object adapter only) 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.

Other issues to consider when using the Adapter pattern:
How much adapting does Adapter do?
Pluggable adapters (By building interface adaptation into a
class, you eliminate the assumption that other classes see the
same interface)
Using two-way adapters to provide transparency. (Two
Structural Design Patterns :
Adapter
                      Deals with the composition of classes or
                      objects
Project Example: Data Adapters (How??)
Thanks

More Related Content

What's hot

Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternMudasir Qazi
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternShahriar Hyder
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design PatternsLidan Hifi
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternMudasir Qazi
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for DummiesTaekSoon Jang
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design PatternAdeel Riaz
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installationPoojaBele1
 
Creational pattern
Creational patternCreational pattern
Creational patternHimanshu
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern11prasoon
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 

What's hot (20)

Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Behavioral Design Patterns
Behavioral Design PatternsBehavioral Design Patterns
Behavioral Design Patterns
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Bridge pattern for Dummies
Bridge pattern for DummiesBridge pattern for Dummies
Bridge pattern for Dummies
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installation
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Jdbc
JdbcJdbc
Jdbc
 

Viewers also liked

Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Patterneprafulla
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator PatternAkshat Vig
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Sameer Rathoud
 
Structural patterns
Structural patternsStructural patterns
Structural patternsHimanshu
 

Viewers also liked (7)

Design Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator PatternDesign Patterns - 01 Introduction and Decorator Pattern
Design Patterns - 01 Introduction and Decorator Pattern
 
Composite Design Pattern
Composite Design PatternComposite Design Pattern
Composite Design Pattern
 
The Decorator Pattern
The Decorator PatternThe Decorator Pattern
The Decorator Pattern
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)Decorator design pattern (A Gift Wrapper)
Decorator design pattern (A Gift Wrapper)
 
Structural patterns
Structural patternsStructural patterns
Structural patterns
 

Similar to Structural Design pattern - Adapter

M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design PatternsDang Tuan
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxdanhaley45372
 
Architecture and design
Architecture and designArchitecture and design
Architecture and designhimanshu_airon
 
UML-Advanced Software Engineering
UML-Advanced Software EngineeringUML-Advanced Software Engineering
UML-Advanced Software EngineeringAmit Singh
 
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad NicheTech Com. Solutions Pvt. Ltd.
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)stanbridge
 
Class and object_diagram
Class  and object_diagramClass  and object_diagram
Class and object_diagramSadhana28
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patternspradeepkothiyal
 
My design patterns
My design patternsMy design patterns
My design patternszenwalker
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityShubham Narkhede
 
Final sdp ppt
Final sdp pptFinal sdp ppt
Final sdp pptnancy_17
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questionsjinaldesailive
 
Advanced Structural Modeling
Advanced Structural ModelingAdvanced Structural Modeling
Advanced Structural ModelingAMITJain879
 

Similar to Structural Design pattern - Adapter (20)

Sda 9
Sda   9Sda   9
Sda 9
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
 
Sda 7
Sda   7Sda   7
Sda 7
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Architecture and design
Architecture and designArchitecture and design
Architecture and design
 
UML-Advanced Software Engineering
UML-Advanced Software EngineeringUML-Advanced Software Engineering
UML-Advanced Software Engineering
 
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
Cocoa and MVC in ios, iOS Training Ahmedbad , iOS classes Ahmedabad
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)Cs 1023 lec 8 design pattern (week 2)
Cs 1023 lec 8 design pattern (week 2)
 
Class and object_diagram
Class  and object_diagramClass  and object_diagram
Class and object_diagram
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
Design patterns
Design patternsDesign patterns
Design patterns
 
My design patterns
My design patternsMy design patterns
My design patterns
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
 
Final sdp ppt
Final sdp pptFinal sdp ppt
Final sdp ppt
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Advanced Structural Modeling
Advanced Structural ModelingAdvanced Structural Modeling
Advanced Structural Modeling
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 

More from Manoj Kumar

Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)
Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)
Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)Manoj Kumar
 
Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)
Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)
Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)Manoj Kumar
 
BizTalk Orchestration Fundamentals
BizTalk Orchestration FundamentalsBizTalk Orchestration Fundamentals
BizTalk Orchestration FundamentalsManoj Kumar
 
BizTalk Messaging Fundamentals
BizTalk  Messaging FundamentalsBizTalk  Messaging Fundamentals
BizTalk Messaging FundamentalsManoj Kumar
 
BizTalk Fundamentals
BizTalk  FundamentalsBizTalk  Fundamentals
BizTalk FundamentalsManoj Kumar
 
Introduction to ASP.Net Mvc3 with Razor
Introduction to ASP.Net Mvc3 with RazorIntroduction to ASP.Net Mvc3 with Razor
Introduction to ASP.Net Mvc3 with RazorManoj Kumar
 
Server vs Client in real life and in programming world
Server vs Client in real life and in programming worldServer vs Client in real life and in programming world
Server vs Client in real life and in programming worldManoj Kumar
 
Html5 Introduction
Html5 IntroductionHtml5 Introduction
Html5 IntroductionManoj Kumar
 
N-Tier Application Architecture
N-Tier Application ArchitectureN-Tier Application Architecture
N-Tier Application ArchitectureManoj Kumar
 

More from Manoj Kumar (9)

Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)
Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)
Cloud Computing – Jump start cloud development with Microsoft Azure (Part-2)
 
Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)
Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)
Cloud Computing – Opportunities, Definitions, Options, and Risks (Part-1)
 
BizTalk Orchestration Fundamentals
BizTalk Orchestration FundamentalsBizTalk Orchestration Fundamentals
BizTalk Orchestration Fundamentals
 
BizTalk Messaging Fundamentals
BizTalk  Messaging FundamentalsBizTalk  Messaging Fundamentals
BizTalk Messaging Fundamentals
 
BizTalk Fundamentals
BizTalk  FundamentalsBizTalk  Fundamentals
BizTalk Fundamentals
 
Introduction to ASP.Net Mvc3 with Razor
Introduction to ASP.Net Mvc3 with RazorIntroduction to ASP.Net Mvc3 with Razor
Introduction to ASP.Net Mvc3 with Razor
 
Server vs Client in real life and in programming world
Server vs Client in real life and in programming worldServer vs Client in real life and in programming world
Server vs Client in real life and in programming world
 
Html5 Introduction
Html5 IntroductionHtml5 Introduction
Html5 Introduction
 
N-Tier Application Architecture
N-Tier Application ArchitectureN-Tier Application Architecture
N-Tier Application Architecture
 

Recently uploaded

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Recently uploaded (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

Structural Design pattern - Adapter

  • 1. Structural Design Patterns : Adapter Manoj Kumar Software Developer manojksh9@gmail.com
  • 2. Design Patterns Design patterns are classified by two criteria: Purpose and scope. Creational: Concerns the process of object creation Structural: Deals with the composition of classes or objects Behavioral: Characterizes the ways in which classes or objects interact and distribute responsibility
  • 3. Design Patterns Purpose: Reflects what a pattern does Scope: Specifies whether the pattern applies primarily to classes or to objec
  • 4. Structural Design Patterns Deals with the composition of classes or objects Structural patterns are concerned with how classes and objects are composed to form larger structures. Structural class patterns use inheritance to compose interfaces or implementations. Example: Multiple inheritance mixes two or more classes into one. Class form of the Adapter pattern: In general, an adapter makes one interface (the adaptee's) conform to another, thereby providing a uniform abstraction of different interfaces.
  • 5. Structural Design Patterns : Adapter Deals with the composition of classes or objects Also Known As Wrapper Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. What is an Adapter/Wrapper? For Example: Shape + TextView = TextShape (Adapter) Drawing editor: Draws lines/polygons, text; Pictures and diagrams Key abstraction: Graphical object (which has an editable shape and can draw itself) The interface for graphical objects: an abstract class “Shape” The editor defines a subclass of Shape for each kind of graphical object: a LineShape class for lines, a PolygonShape class for polygons
  • 6. Structural Design Patterns : Adapter Deals with the composition of classes or objects TextShape subclass: Display and edit, so considerably more difficult to implement as complicated screen update and buffer management are required How to write this ‘TextShape’ subclass? User interface toolkit (Already provide a sophisticated TextView class for displaying and editing text) A problem: Toolkit wasn't designed with Shape classes in mind. So we can't use TextView and Shape objects interchangeably. How can existing and unrelated classes like TextView work in an application that expects classes with a different and incompatible interface? Solution: A new class “TextShape” Adapts the TextView interface to Shape's An Adapter (Class version-by Inheriting Object version-by composing)
  • 7. Structural Design Patterns : Adapter Deals with the composition of classes or objects Identify?? Class or Object
  • 8. Structural Design Patterns : Adapter Deals with the composition of classes or objects
  • 9. Structural Design Patterns : Adapter Deals with the composition of classes or objects Participants Target (Shape) defines the domain-specific interface that Client uses. Client (DrawingEditor) collaborates with objects conforming to the Target interface. Adaptee (TextView) defines an existing interface that needs adapting. Adapter (TextShape) adapts the interface of Adaptee to the Target interface. Collaborations Clients call operations on an Adapter instance. In turn, the adapter calls Adaptee operations that carry out the request.
  • 10. Structural Design Patterns : Adapter Deals with the composition of classes or objects Consequences Class and object adapters have different trade-offs. A class adapter adapts Adaptee to Target by committing to a concrete Adapter class. As a consequence, a class adapter won't work when we want to adapt a class and all its subclasses. lets 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. An object adapter lets 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 all Adaptees at once. makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.
  • 11. Structural Design Patterns : Adapter Deals with the composition of classes or objects Applicability You want to use an existing class, and its interface does not match the one you need. You want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces. (object adapter only) 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. Other issues to consider when using the Adapter pattern: How much adapting does Adapter do? Pluggable adapters (By building interface adaptation into a class, you eliminate the assumption that other classes see the same interface) Using two-way adapters to provide transparency. (Two
  • 12. Structural Design Patterns : Adapter Deals with the composition of classes or objects Project Example: Data Adapters (How??)

Editor's Notes

  1. A class adapter accomplishes this by inheriting privately from an adaptee class. The adapter then expresses its interface in terms of the adaptee's.