The Adapter Pattern.

Slides:



Advertisements
Similar presentations
CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Advertisements

SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
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.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Patterns – Day 4 Interfaces and Adapter Reminders: Faculty candidate talks Monday and Thursday. No class on Monday.
Chapter 8, Object Design Introduction to Design Patterns
Feb Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface the client expects. An adapter lets classes work.
Patterns – Day 6 Adapter continued Reminders: Faculty candidate talk today 4:20 PM O-167. No class next Tuesday. Course newsgroup: rhit.cs.patterns.
March Ron McFadyen1 Adapter An adapter converts the interface of a class into another interface clients expect. An adapter lets classes work.
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.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
Patterns – Day 5 Adapter Reminders: Faculty candidate talk Thursday. No class next Tuesday. Course newsgroup: rhit.cs.patterns.
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.
Object Adapter Pattern Danny Leavitt. Imagine... You program for the control center of a US phone company. Your network managment software is Object Oriented.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
Computer Science 313 – Advanced Programming Topics.
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.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
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.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Frameworks & Patterns Use of Organized Classes. Frameworks vs Toolkits Framework Framework  Start with classes and interfaces that define a rudimentary.
Structural Design Patterns
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Chapter 7: The Adapter Pattern. Object Oriented Adapters Suppose that you have existing software. You have outsourced some of your work and there is a.
Class & Object Adapter Patterns (with a focus on Class Adapter) Tim Gutowski CSPP 51023, Winter 2008.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
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.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
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.
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.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Abstract Classes and Interfaces
Abstract Classes and Interfaces
Design Patterns Lecture part 2.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
By SmartBoard team Adapter pattern.
Adapter Design Pattern
GUI AND GRAPHICS.
ABSTRACT FACTORY.
by Manish Shah & Eugene Park CSPP 523 Jan.21, 2002
Behavioral and Structural Patterns
Adapter Pattern 1.
Week 6 Object-Oriented Programming (2): Polymorphism
Object Oriented Design Patterns - Structural Patterns
BRIDGE PATTERN.
Why inheritance? shape mammal map
Structural Patterns: Adapter and Bridge
Adapter Design Pattern
PATTERNS.
Software Design Lecture : 34.
Decorator Pattern.
Adapter Pattern Jim Fawcett
Adapter Pattern Jim Fawcett
Presentation transcript:

The Adapter Pattern

Problem Specification: You are given the following class library to draw shapes. Shape +display() +fill() +undisplay() Line Square

2. Now you are asked to add another class to deal with circle 2. Now you are asked to add another class to deal with circle. Your plan was: Shape +setLoccation() +getLocation() +display() +fill() +undisplay() Line Square Circle +display() +fill() +setColor() +undisplay()

3. Then your client said: “No,no,no” 3. Then your client said: “No,no,no”. You have to use this nice class library for drawing circles. Unfortunately, it is from a different vendor and it has a different interface. Shape +display() +fill() +undisplay() Line Square AnotherCircle +setLocation() +drawIt() +fillIt() +setItColor() +unDrawIt()

Two kinds of adapter pattern Object adapter pattern The adapter class contains adaptee object Class adapter pattern Adapter class is inherited from both adaptee and abstract class

Object Adapter AbstractClass AdapterClass AdapteeClass

Adapter Design Pattern Solution Object Adapter Shape +display() +fill() +undisplay() Line Square adaptee adapter Circle -aCircle:AnotherCircle +display() +fill() +undisplay() AnotherCircle +setLocation() +drawIt() +fillIt() +setItColor() +unDrawIt() void display(){ aCircle.drawIt(); } void fill(){ aCircle.fillIt(); } void undisplay(){ aCircle.unDrawIt(); }

class Circle extends Shape { … private AnotherCircle anotherCircle; public Circle(){ anotherCircle = new AnotherCircle(); } public void display() another.displayIt();

class Client { … Shape aShape = new Circle; aShape.display(); //call Circle::display () }

Class Adapter AdapteeClass AbstractClass AdapterClass

Adapter Design Pattern Solution Class Adapter Shape +display() +fill() +undisplay() Line Square AnotherCircle +setLocation() +drawIt() +fillIt() +setItColor() +unDrawIt() Circle +display() +fill() +undisplay() void display(){ drawIt(); } void fill(){ fillIt(); } void undisplay(){ unDrawIt(); }

Adapter pattern Intent Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. 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