Department of Computer Science, York University Object Oriented Software Construction 13/10/2015 10:44 AM 0 CSE3311 – Software Design Adapter Pattern.

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

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.
Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
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.
R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
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,
Design Pattern – Bridge (Structural) References Yih-shoung Chen, Department of Information Engineering, Feng Chia University,Taiwan, R.O.C. The Bridge.
Chapter 22 Object-Oriented Design
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
1 Dept. of Computer Science & Engineering, York University, Toronto Software Development CSE3311 Composite Pattern.
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.
Department of Computer Science, York University Object Oriented Software Construction 16/09/ :52 PM 0 COSC3311 – Software Design Decorator Pattern.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
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.
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
Learning to Program with C# - 61 Unit 6 Reflection on the C# Model of Computation introduced so farReflection on the C# Model of Computation introduced.
Decorator Explained. Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
By Shishir Kumar Contact:
Structural Design Patterns
More Design Patterns Horstmann ch.10.1,10.4. Design patterns Structural design patterns –Adapter –Composite –Decorator –Proxy Behavioral design patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Computer Science 209 The Adapter Pattern. The Context of the Adapter Pattern I want to use an existing class (the adaptee) without modifying it The context.
Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
Introduction to OOP CPS235: Introduction.
S.Ducasse Stéphane Ducasse 1 Decorator.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
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.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Design Patterns Lecture part 2.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
By SmartBoard team Adapter pattern.
Behavioral Design Patterns
Adapter Design Pattern
Satisfying Open/Closed Principle
Section 11.1 Class Variables and Methods
by Manish Shah & Eugene Park CSPP 523 Jan.21, 2002
Design Patterns A Case Study: Designing a Document Editor
Adapter Pattern 1.
Object Oriented Design Patterns - Structural Patterns
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Structural Patterns: Adapter and Bridge
Introduction to Design Patterns
Adapter Design Pattern
The Adapter Pattern.
Adapter
Informatics 122 Software Design II
Decorator Pattern.
Adapter Pattern Jim Fawcett
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern

Department of Computer Science, York University Non-software analogy  North American equipment electricity requirements: 110V, 60 Hz.  European electricity: 220V, 50 Hz.  Not practical to oBuy new equipment (computer, ipod etc) when traveling oBuild a new electricity transmission system while in Europe  Solution oUse an adapter

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 2 Adapter Pattern Intent  Convert the interface of a class into another interface that clients expect.  Adapter lets classes with otherwise incompatible interfaces work together.

Department of Computer Science, York University Design Example Object Oriented Software Construction 13/10/ :44 AM 3 Our windowing toolkit has a drawing editor with class SHAPE with bounding box: bottom_left, top_right: POINT2D Classes such as LINE and POLYGON inherit from SHAPE An off the shelf user interface toolkit (e.g. a.NET component) has a TEXT_VIEW to display and edit text with sophisticated screen update and buffering capabilities. It’s bounding box is: origin: POINT2D width, height: REAL

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 4 Requirement  We would like to re-use TEXT_VIEW as a SHAPE  However, they have incompatible interfaces

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 5 Design 1  Change the TEXT_VIEW class’ features so that it’s interface is compatible with SHAPE  Problem: We don’t have TEXT_VIEW’s source code – hence it is fixed in stone (e.g. a.NET assembly).  Even if we have the source code, why should we have to change the interface just to make one application work. oRecall the open-closed principle

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 6 Design 2  Recall the open-closed principle  Adapter Pattern

Department of Computer Science, York University Adapter – Context  You want to use an existing class (TEXT_VIEW) without modifying it oAdaptee  The context in which you want to use the class requires conformance to an interface that is different from that of the adaptee oTarget (SHAPE)  The target interface and the adaptee interface are conceptually related

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 8 SHAPE vs. TEXT_VIEW  SHAPE’s assumes a bounding box defined by its opposing corners  TEXT_VIEW is defined by its origin, height and width.

Department of Computer Science, York University Adapter – Solution  Define an adapter class (TEXT_SHAPE) that implements the target interface  The adapter class holds a reference to the adaptee. It translates target methods to adaptee methods

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 10 Two Kinds of Adapters  TEXT_SHAPE inherits SHAPE's interface and TEXT_VIEW's implementation. oInheritance/class Adapter  TEXT_SHAPE2 inherits SHAPE's interface and uses TEXT_VIEW's implementation. oClient-Supplier Adapter (also mistakenly called object adapter)

Department of Computer Science, York University Client-supplier adaptor Object Oriented Software Construction 13/10/ :44 AM 11

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 12 Inheritance adapter

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 13 Participants  Target (SHAPE) odefines the domain-specific interface that Client uses.  Client (DrawingEditor) ocollaborates with objects conforming to the Target interface.  Adaptee (TEXT_VIEW) odefines an existing interface that needs adapting.  Adapter (TEXT_SHAPE) oadapts the interface of Adaptee to the Target interface.

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 14 Applicability  Use the Adapter pattern when oyou want to use an existing class, and its interface does not match the one you need. oyou want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces. o(client-supplier adapter only) you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. A client-supplier adapter can adapt the interface of its parent class.

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 15 Consequences  Class and object adapters have different trade-offs.  An inheritance adapter owon't work when we want to adapt a class and all its subclasses. olets Adapter override some of Adaptee's behavior, since Adapter is a subclass of Adaptee. ointroduces only one object, and no additional pointer indirection is needed to get to the adaptee.  A client-supplier adapter olets 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. omakes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.

Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 16 Eiffel has rich adapter mechanisms  Rename  Redefine  Changing export status  OOSC2 chapter 15 (Multiple inheritance) oUndefine oSelect

Department of Computer Science, York University Adapter real-world examples  java.io.Reader is an abstract class for reading character streams [TARGET] oContains an abstract method read(char[],int,int)  java.io.InputStream represents an input stream of bytes [ADAPTEE] oContains method read(byte[],int,int)  java.io.InputStreamReader is an adapter from byte streams to character streams [ADAPTER] oImplements read(char[],int,int) using read(byte[],int,int)

Department of Computer Science, York University code  adapter.zip Object Oriented Software Construction 13/10/ :44 AM 18