Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008.

Slides:



Advertisements
Similar presentations
Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
Ch 12: Object-Oriented Analysis
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
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,
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Unified Modeling Language
CS 4240: Introduction to Design Patterns Readings: Chap. 5 of Design Patterns Explained Also, Chap. 6 and 7 Also, on-line info on Composite pattern (and.
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.
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.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
GoF Sections Design Problems and Design Patterns.
Patterns COM379 University of Sunderland James Malone.
By Shishir Kumar Contact:
Structural Design Patterns
COMP 121 Week 12: Decorator and Adapter 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.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Inheritance Revisited Other Issues. Multiple Inheritance Also called combination--not permitted in Java, but is used in C++ Also called combination--not.
Object-Oriented Programming. Objectives Distinguish between object-oriented and procedure-oriented design. Define the terms class and object. Distinguish.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
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.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Structural Design Pattern: CLASS ADAPTER a.k.a. WRAPPER By Ed Kim.
S.Ducasse Stéphane Ducasse 1 Adapter.
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
Design Patterns: Brief Examples
Design Patterns C++ Java C#.
By SmartBoard team Adapter pattern.
The Object-Oriented Thought Process Chapter 1
Chapter 11 Object-Oriented Design
Design Patterns C++ Java C#.
Adapter Design Pattern
Satisfying Open/Closed Principle
Design Patterns with C# (and Food!)
Adapter, Fascade, and More
7. Decorator, Façade Patterns
by Manish Shah & Eugene Park CSPP 523 Jan.21, 2002
Adapter Pattern 1.
Code reuse through subtyping
Structural Patterns: Adapter and Bridge
Introduction to Design Patterns
Adapter Design Pattern
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
2009 Test Key.
Software Design Lecture : 34.
Adapter Pattern Jim Fawcett
Adapter Pattern Jim Fawcett
Presentation transcript:

Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008

Adapter Pattern: What/when? The class adapter pattern allows two unrelated interfaces to work together. If a client would like to use an existing class, but does not have a compatible interface, they can still utilize it by using a class adapter. Because the adapter often “wraps” around an existing interface, this adapter is also known as a “wrapper.”

Adapter Pattern: Why? You would use a class adapter if a given class has a proven method you would like to call with one of your objects … But for whatever reason, your client’s interface doesn’t match the target’s. This allows developers to re-use code and avoids the scenario where a perfectly good class has to be modified simply to fit your class’ interface.

Example: Interface adaptation My problem: I would like to be able to display my computer screen onto my big-screen TV…allowing me to more comfortably work on HW from my couch.

Standard interface: VGA And the good people at Sony have even provided an interface to do so …

Problem: Wrong interface But…of course, the TV requires a VGA interface, and my computer only has a DVI interface.

Solution: An adapter Lo and behold, Apple machines all ship with a DVI to VGA adapter.

Class adapter deployed The adapter allows incompatible interfaces to work together …

Adaptation complete … so I can work on UML documents while laying on my couch. (Note: requires wireless keyboard)

Example UML Adapter class uses inheritance to get its domain-specific and adaptee interface information. Being a subclass, it can override certain adaptee behaviors.

Example PseudoCode /* The Sony interface has a VGA output */ public interface Sony_VGA {... public String ConnectVGA();... } /* class Apple wants a DVI input public class Apple { private String specification = "DVI"; public String connectDVI() { return specification; } /* Finally, there will be an adapter class called connector. This will inherit the Sony_VGA and give output for Apple. */ public class connector implements Sony_VGA { public String ConnectVGA { Connector connector = new Connector(); String output = connector.connectDVI(); return output; }

Another Basic Example A class that performs a set of regex matching operations which you’d like to apply to some dictionaries in a separate object. Problem: Class interface requires individual string inputs. Adapter converts your dict to a series of strings and utilizes adaptee.

Object Adapter Compositional instead of inheritance- based, which GoF book prefers. In this case, adapter wraps an actual instance of the adaptee and calls operations on it. Allows a single adapter to work with multiple adaptees, which isn’t the case with class adapter.

Summation Use the Adapter pattern when you want to use an existing class but its interface doesn’t match what you require. Use it to create a reusable converter class that is can deal with unforeseen classes/incompatible interfaces. Work with multiple adaptees (subclasses of parent adaptee) with object adapter.