Adapter Pattern Jim Fawcett

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
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.
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.
Patterns – Day 4 Interfaces and Adapter Reminders: Faculty candidate talks Monday and Thursday. No class on Monday.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
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,
Chapter 10 Classes Continued
Patterns – Day 5 Adapter Reminders: Faculty candidate talk Thursday. No class next Tuesday. Course newsgroup: rhit.cs.patterns.
Chapter 22 Object-Oriented Design
© SERG Software Design (OOD Patterns) Object-Oriented Design Patterns Topics in Object-Oriented Design Patterns Compliments of Spiros Mancoridis Material.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
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.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008.
Design Patterns Introduction
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.
S.Ducasse Stéphane Ducasse 1 Decorator.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
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.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Modern Programming Tools And Techniques-I
Factory Method Pattern
Design Patterns Spring 2017.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
By SmartBoard team Adapter pattern.
Introduction with a few design patterns
Software Design and Architecture
Adapter Design Pattern
Satisfying Open/Closed Principle
Flyweight Design Pattern
Factory Method Pattern
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
CSE870: Advanced Software Engineering (Design Patterns): Cheng, Sp2003
Jim Fawcett CSE776 – Design Patterns Summer 2003
State Design Pattern 1.
Adapter Pattern 1.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Structural Pattern part-I introduction
Structural Patterns: Adapter and Bridge
Adapter Design Pattern
Adapter
Decorator Pattern.
Adapter Pattern Jim Fawcett
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Software Design Lecture 10.
Message Passing Systems
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Adapter Pattern Jim Fawcett CSE687 – Object Oriented Design, Spring 2003 Adapted from a Presentaton by Matt Smouse and Jeff Ting CSE776 – Design Patterns, Summer 2001

Intent Adapt an existing class rather than modify for reuse: Convert interface of a useful class into another interface clients expect Also known as the wrapper design pattern; it wraps existing functionality of an adaptee with an adapter’s inherited interface.

Motivation TextView example Client is a drawing editor which wants to accommodate both shapes and text. Adaptee is an existing TextView class which can display and edit text. Target is a Shape class which provides the key abstraction for graphical objects. Adapter is a TextShape class which inherits the Shape interface and adapts the TextView interface to the inherited Shape interface.

Motivation: Class Adapter DrawingEditor Shape TextView BoundingBox( ) CreateManipulator( ) GetExtent( ) Line TextShape BoundingBox( ) CreateManipulator( ) BoundingBox( ) CreateManipulator( )

Motivation: Object Adapter DrawingEditor Shape TextView BoundingBox( ) CreateManipulator( ) GetExtent( ) text Line TextShape BoundingBox( ) CreateManipulator( ) BoundingBox( ) CreateManipulator( )

Applicability Use an adapter when you have existing classes and need to add functionality while providing a common interface. Use an adapter when you want a reusable class which will handle software that you did not write. Use an object adapter when you have to provide for several different adaptee subclasses which inherit from a parent* adaptee. *Must use object adapter when adaptee is abstract.

Structure: Class Adapter Client Target Adaptee Request( ) SpecificRequest( ) (implementation) Adapter Request( ) SpecificRequest( )

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

Participants Target Client Adaptee Adapter defines the interface that the Client will use. Client creates and interacts with objects which conform to the target interface. Adaptee has an interface that needs adapting. Adapter adapts the interface of the adaptee to that of the target.

Collaborators Clients will create instances of the adapter and any adaptees to be used. Clients will call operations within instances of the adapter. The adapter will call adaptee operations on behalf of the client. The adapter may or may not perform additional processing on any data that the adaptee methods return. The adapter is the middleman for all operations involving the adaptee.

Consequences Class Adapter Object Adapter Must commit to a concrete adaptee. This won’t work for an abstract adaptee, and it won’t work when adapting multiple adaptees. The adapter can override some of the adaptee’s behavior; the adapter is a subclass (child) of the adaptee. No additional pointer indirection to access adaptee. Object Adapter Can work with adaptee subclasses and add functionality to those subclasses. The adapter cannot easily override adaptee behavior; only can do this by referring to an adaptee subclass.

Implementation: Class Adapter Based upon multiple inheritance Inherit publicly from Target (the interface) and privately from Adaptee (the implementation) Adaptor is a subtype of Target but not of Adaptee

Implementation: Object Adapter Only inherits (publicly) from Target Adapter maintains pointer to Adaptee; Client must initialize this pointer Will work with subclasses of Adaptee

Pluggable Adapter Special object adapter Make the target contain abstract (pure virtual) methods. Provide concrete operations which are common to any adapter implementation. Provide abstract (pure virtual methods) operations which are required for unique adaptation. Limit the number of abstract operations; it is easier to adapt a few necessary operations than to adapt many. The client will instantiate the adapter it wishes to use; since all adapters will conform to the target interface, we can swap them in and out of the client and it won’t know the difference (beyond instantiation).

Two-way Adapter Based upon multiple inheritance Inherits publicly from both classes (interfaces) Two Adaptees, no Target Used to combine functionality of two unlike classes

Two-way Adapter Adaptee1 Adaptee2 Adapter

Known Uses ET++Draw InterViews 2.6 Pluggable adaptors in Smalltalk FixedStack ACE ORB (?) Java applications (object adapters only)

Related Patterns Bridge Decorator Proxy Separates an interface from its implementation. Adapter works with existing object. Decorator Enhances another object without changing interface. Adapter is less transparent to the client. Proxy Representative for another object, no interface change Adapter changes (adapts) the object’s interface.

End of Presentation