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,

Slides:



Advertisements
Similar presentations
Design Patterns based on book of Gang of Four (GoF) Erich Gamma, Richard Helm, Ralph Johnson, and John VlissidesGang of Four (GoF) Elements of Reusable.
Advertisements

GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Design Patterns Yes, they are important Robert Cotton April 23, 2009.
Chapter 6: Using Design Patterns
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.
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Design Patterns Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson,Ralph Johnson and John Vlissides (The Gang of.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
Implementing Design Patterns Using Java St. Louis Java Special Interest Group Eric M. Burke Object Computing, Inc. Presented on July 9, 1998 (updated July.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns 1.
Introduction To System Analysis and Design
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
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.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
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.
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
© 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1 Broker Design Patterns: Adapters and Proxy.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Software Design Refinement Using Design Patterns
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Introduction
Introduction with a few design patterns
Adapter Design Pattern
Instructor: Dr. Hany H. Ammar
Presented by Igor Ivković
Chapter 6: Using Design Patterns
Advanced Programming Behnam Hatami Fall 2017.
Adapter Pattern 1.
DESIGN PATTERNS : Introduction
Structural Patterns: Adapter and Bridge
Adapter Design Pattern
Introduction to Design Patterns
Adapter
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Composite Design Pattern By Aravind Reddy Patlola.
Presented by Igor Ivković
Adapter Pattern Jim Fawcett
Adapter Pattern Jim Fawcett
Presentation transcript:

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, (the adapter) that delegates to the adaptee. AKA: Wrapper

Typical Context 1.You are building an inheritance hierarchy and you want to incorporate into it a class written by somebody else - i.e. you want to reuse an existing class. 2.Typically the methods of the reused class do not have the same name or argument types as the methods in the hierarchy you are creating. 3.The reused class is also often already part of its own inheritance hierarchy.

Problem How do you obtain the power of polymorphism when reusing a class whose methods have the same function but do not have the same signature as the other methods in the hierarchy?

Solution 1.Rather than directly incorporating the reused class into your inheritance hierarchy, instead incorporate an «Adapter» class. 2.The «Adapter» is connected by an association to the reused class, which we will call the «Adaptee». 3.The polymorphic methods of the «Adapter» delegate to methods of the «Adaptee».

A Drawing Program Example Consider a drawing editor. Top level data type is the “graphical object” Subclasses of the “graphical object” class: LineShape, PolygonShape, TextShape etc.

The TextShape Class The TextShape class is considerably more difficult to implement than simple polygon classes. We have a user-interface toolkit which provides a reusable “TextView” class for displaying and editing text. TextView was not developed with our shape-class oriented design in mind. Sounds like we need an adapter!

Interface Differences 1.TextView uses different names for it’s functions. 2.TextView lacks the functionality for interactive “dragging” of text etc, which our graphical object requires.

Adapter’s Solutions 1.The Adapter provides our graphical object class with functions under the expected name which simply call the appropriate functions in TextView. 2.The Adapter can contain additional functions such as a “TextManipulator” which will be responsible for the unsupported functionality.

Structure 1.Class Adapter –Uses multiple inheritance to adapt one interface to another. 2.Object Adapter –Relies on object composition.

Adapter Class Diagram (Class Adapter) Client Target Request() Adaptee SpecificRequest() Adapter Request() SpecificRequest() (implementation)

(class) Adapter Class Diagram: Example by Rob Kremer, Professor of Computer Science at Calgary University Client Target Request() Adaptee SpecificRequest() Adapter Request() SpecificRequest() (implementation) List InsertAtFront() Get Front() RemoveFront() Queue Push() Pop() QueueImp Push() Pop() InsertAtFront() We have a list… We want a queue… Adapter to the rescue! x := GetFront(); RemoveFront(); return x;

Consequences (Class Adapter) The class adapter adapts adaptee to the target interface by committing to a concrete adaptee class. Thus a class adapter won’t work when we want to adapt a class and all it’s subclasses. The adapter can override some of adaptee’s behavior, since the adapter is a subclass of the adaptee. It introduces only one object, thus no additional pointer indirection is needed to get to the adaptee.

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

Client Target Request() Adaptee SpecificRequest() Adapter Request() SpecificRequest() (implementation) Use a pointer to an instance of the the adaptee Change the code of Request() to use the pointer Adaptee->SpecificRequest() adaptee (object) Adapter Class Diagram: Example by Rob Kremer, Professor of Computer Science at Calgary University

Consequences (Object Adapter) Using an object adapter let’s a single adapter work with many adaptees, i.e.. the adapter itself and all it’s subclasses. It also makes it harder to override adaptee behavior. Doing so will require subclassing adaptee and making adapter refer to the subclass instead of the adapter itself.

Things to keep in mind for Adapters 1.should be as general as possible 2.should be described in an easy-to- understand form so that people can determine when and how to use it 3.should contain a solution that has been proven to effectively solve the problem in the indicated context 4.should be illustrated using a simple diagram 5.should be written using a narrative writing style

Adapters are one of the Gang of Four patterns Others include: Facade Read-only interface Proxy

References: Design Patters: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Object Oriented Software Engineering Knowledge Base, Knowledge base was created from the book "Object Oriented Software Engineering: Practical Software Development using UML and Java“ by Timothy C. Lethbridge and Robert Laganière published by McGraw Hill in Summer Diagrams taken from Prof Rob Kremer’s “Notes from Design Patterns: Elements of Reusable Object-Oriented Software, The Adapter and Bridge Patterns”