ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.

Slides:



Advertisements
Similar presentations
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Advertisements

1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
02 - Structural Design Patterns – 1 Moshe Fresko Bar-Ilan University תשס"ח 2008.
PATTERNS -STRUCTURAL PATTERNS WATTANAPON G SUTTAPAK Software Engineering, School of Information Communication Technology, University of PHAYAO 1.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Structural Patterns - Page L6-1 PS95&96-MEF-L13-1 Dr. M.E. Fayad Creationa l Paradigm.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
Adapters Presented By Zachary Dea. Definition A pattern found in class diagrams in which you are able to reuse an ‘adaptee’ class by providing a class,
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Client/Server Software Architectures Yonglei Tao.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Patterns.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Object Adapter Pattern Danny Leavitt. Imagine... You program for the control center of a US phone company. Your network managment software is Object Oriented.
Computer Science 313 – Advanced Programming Topics.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Design Patterns – II Lecture IV. Singleton Pattern Intent – Ensure a class only has one instance, and provide a global point of access to it Motivation.
SDP Structural Pattern. SDP-2 Structural Patterns Concerned with how classes and objects are composed to form large structures Class Patterns use.
By Shishir Kumar Contact:
Structural Design Patterns
ECE450S – Software Engineering II
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
Creational Patterns
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
Bridge Bridge is used when we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
CS 350 – Software Design The Adapter Pattern – Chapter 7 Gang of Four Definition: Convert the interface of a class into another interface that the client.
S.Ducasse Stéphane Ducasse 1 Adapter.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Adapters and Proxy.
Structural Patterns C h a p t e r 4 – P a g e 55 StructuralPatterns Design patterns that describe how classes and objects can be combined to form larger.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Describe ways to assemble objects to implement a new functionality
Chapter 10 Design Patterns.
Design Patterns Lecture part 2.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
By SmartBoard team Adapter pattern.
Introduction to Design Patterns
Adapter Design Pattern
Design Patterns with C# (and Food!)
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
by Manish Shah & Eugene Park CSPP 523 Jan.21, 2002
Jim Fawcett CSE776 – Design Patterns Summer 2003
Adapter Pattern 1.
Object Oriented Design Patterns - Structural Patterns
What is Adapter Category: Structural Also known as ‘Wrapper’
Structural Pattern part-I introduction
Structural Patterns: Adapter and Bridge
Adapter Design Pattern
The Adapter Pattern.
Adapter
Decorator Pattern.
Adapter Pattern Jim Fawcett
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

ADAPTER PATTERN BY Sravanthi Karumanchi

Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures. Different categories Adapter Bridge Composite Decorator Façade Flyweight Proxy

Scenario Outlets and Plugs Outlets in the US require a certain kind of plug. For example, a plug made in India for Indian outlet may not be used in USA. To use these appliances in USA or vice-versa we may need to purchase an adapter.

Motivation Sometimes a toolkit or class library can not be used because its interface is incompatible with the interface required by an application. We can not change the library interface, since we may not have its source code. Even if we did have the source code, we probably should not change the library for each domain- specific application.

Adapter Pattern Adapters are used to enable objects with different interfaces to communicate with each other. Adapter Pattern tells us how to wrap up existing classes inside a new target interface, when the need arises to reuse existing class implementations but with a different interface for the clients. They are also termed as wrappers.

Variations in Adapters Class Adapters Use multiple inheritance to compose classes Object Adapters Object adapters use a compositional technique to adapt one interface to another.

Object Pattern Client Target Request( ) Adaptee SpecificRequest ( ) Adapter Request( ) Adaptee->SpecificRequest( ) adaptee

Object Adapter Example Representation ApplicationAdaptationLegacy System Financial amount() Client FinancialAdapter amount() Principal ComputeValue() Legacy Adaptee {legacyadaptee.ComputeValue();}

Class Pattern Client Target Request( ) Adaptee SpecificRequest ( ) Adapter Request( ) Adaptee->SpecificRequest( ) implementation

Class Adapter Example Target Class class RoundPeg { public: void virtual roundPegOperation = 0; } Adaptee Class class OldSquarePeg { public: void squarePegOperation() {{ do something } } Adapter Class class PegAdapter: private OldSquarePeg, public RoundPeg { public: void virtual roundPegOperation() { add some corners; squarePegOperation(); } } Client void clientMethod() { RoundPeg* aPeg = new PegAdapter(); aPeg->roundPegOperation(); }

Object Adapter Example Target Class class RoundPeg { public: void virtual roundPegOperation = 0; } Adaptee Class class OldSquarePeg { public: void squarePegOperation() { do something } } Adapter Class class PegAdapter: public RoundPeg { private: OldSquarePeg* square; public: PegAdapter() { square = new OldSquarePeg; } void virtual roundPegOperation() { add some corners; square- >squarePegOperation(); }

Collaboration Clients call operations on the Adapter instance and Adapter delegates request to Adaptee. ClientsAdapterAdaptee request delegate

Adaptability Use the adapter when Want to use an existing class and its interface doesn’t match the one we need. (Object Adapters only) we need to use several existing subclasses, but it’s impractical to adapt their interface by sub classing every one. An object adapter can adapt the interface of its parent class.

Consequences Class Adapter Adapts Adaptee to Target by committing to a concrete Adapter class. Lets Adapter override some of the Adaptee’s behavior by subclassing. Introduces only one object and no additional pointer indirection is needed to get the adaptee. Object Adapter Lets a single adapter work with a group of adaptees such as a base class and all its sub classes. The adapter can add functioanlity to all adaptees at once. Makes it harder to override Adaptee behavior as the Adapter may not know with what Adaptee it is working with.

How much adapting should be done? The amount of work Adapter does depends on how similar the Target Interface is to Adapteee’s Does the adapter provide two-way transparency? A two-way adapter supports both the Target and the Adaptee interface. It allows an adapted object (Adapter) to appear as an Adaptee object or a Target object. Implementation Issues

Two-way Adapter A two-way adapter would also allow a RoundPeg be used in place of the SquarePeg class OldSquarePeg { public: void virtual squarePegOperation() { function } } class RoundPeg { public: void virtual roundPegOperation() { function } } class PegAdapter: public OldSquarePeg, RoundPeg { public: void virtual roundPegOperation() { add some corners; squarePegOperation(); } void virtual squarePegOperation() { add some corners; roundPegOperation(); } }

Pluggable Adapters A class is more reusable when you minimize the assumptions other classes must make to use it.This is achieved by building interface adaptation.