By SmartBoard team Adapter pattern.

Slides:



Advertisements
Similar presentations
Chapter 8, Object Design Introduction to Design Patterns
Advertisements

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.
Reuse Activities Selecting Design Patterns and Components
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Client/Server Software Architectures Yonglei Tao.
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.
SOFTWARE DESIGN AND ARCHITECTURE
Computer Science 313 – Advanced Programming Topics.
Design Patterns: Structural Design Patterns
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
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.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
By Shishir Kumar Contact:
Structural 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.
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.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
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.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
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.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
S.Ducasse Stéphane Ducasse 1 Adapter.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
A Method for Improving Code Reuse System Prasanthi.S.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Object-Orientated Analysis, Design and Programming
Design Patterns: Brief Examples
Describe ways to assemble objects to implement a new functionality
GoF Patterns (GoF) popo.
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
MPCS – Advanced java Programming
Pertemuan 08 Design Patterns & Anti-Patterns
Behavioral Design Patterns
Design Patterns with C# (and Food!)
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by Igor Ivković
Chapter 8, Object Design Introduction to Design Patterns
Advanced Programming Behnam Hatami Fall 2017.
Adapter Pattern 1.
Object Oriented Design Patterns - Structural Patterns
Object-Oriented Programming
Structural Pattern part-I introduction
Structural Patterns: Adapter and Bridge
Adapter Design Pattern
10. Façade Pattern SE2811 Software Component Design
Presented by Igor Ivković
Adapter Pattern Jim Fawcett
Adapter Pattern Jim Fawcett
GoF Patterns Ch. 26.
Presentation transcript:

By SmartBoard team Adapter pattern

Agenda Problem & Exercises Definition of Adapter Object Adaptor Class Adaptor Pros and Cons References

Problems… Mr. John 110 volts 220 volts

How to fix it ? Please help Mr. John.. 110 volts 220 volts

Definition Wrapper pattern An Adapter pattern convert the interface of a class into another interface client expect It allows classes to work together that normally could not because of incompatible interfaces by wrapping its incompatible interface with another interface client expect The adapter pattern is used so that two or more unrelated interfaces can work together

For more understandable Your code External library 110101101 101010110 101110111 001101101 110101101 101010110 101110111 001101101 Adapter

When to use Adapter ? You want to use an existing class, and its interface doesn’t match with the others you need You want to create a reusable co-op class that cooperates with unrelated classes with incompatible interfaces

Ways to implement adaptor We have 2 ways to implement Object Adaptor Class Adaptor A class which user uses Client class A class/interface that you want to convert to Target class/interface Adaptee class A class that is being adapted

Object Adaptor Or we can call Object Composition

Example : Object Adapter We need to implement Stack But only library we have is Linked Lists Adaptee Target

Class Adaptor Multiple Inheritance Can’t do in JAVA

Example : Class Adaptor We have Turkey and Duck And we want Duck to make sounds like Turkey Target Adaptee

Object Adaptor Pros Cons More flexible than class Adapter Doesn't require sub-classing to work Adapter works with Adaptee and all of its subclasses Cons Harder to override Adaptee behaviour Requires more code to implement properly

Class Adaptor Pros Cons Only 1 new object, no additional indirection Less code required than the object Adapter Can override Adaptee's behaviour as required Cons Requires sub-classing (tough for single inheritance) Less flexible than object Adapter

Pros and Cons Pros Let the different interface classes can work together Easy maintainable for adaptor class Increase the ability of the particular class from adapting the other classes Cons Required multiple inheritances in class adaptor, some prog. languages are not supported If adaptee class is huge and some part of it is not used, adaptor class will be big unnecessarily.

Facade pattern

Why use facade? One Happy Meal

Why use facade?(Cons) I need Happy meal 2 sets I need Set 1 -One burger -One Soda(small) -One French Fries(Small) - 10% discount adding I need lunch special

Why use facade? (cons.) Solve the problem Get these commands to our pos machine. Why use facade? (cons.) Ok, Let’s use the facade pattern to solve it. Solve the problem Set 1 Happy Meal Set A Special Lunch Set 2

Definition Make a complex system simpler by providing a unified or general interface, which is a higher layer to these subsystems make a software library easier to use and understand, since the facade has convenient methods for common tasks reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system; wrap a poorly designed collection of APIs with a single well-designed API (As per task needs).

Facade Structure

Easy Example FileFacade private FileCreator creator = new FileCreator(); private FileRemover remover = new FileRemover(); private FileDuplicator duplicator = new FileDuplicator(); New File creator.createFile(); Delete File remover.removeFile(); Move File duplicator.cloneFile(); remover.removeFile(); Copy File duplicator.cloneFile(); Rename File duplicator.cloneFile(); remover.removeFile();

Complex Example SwingFacade

Pros & Cons Pros Cons Hides the implementation from clients, Reduces class dependencies in large systems Easier to reuse or maintain if the routine is changed, or even there’s a new routine. Cons The subsystem class is not encapsulated, clients still can access it.

References http://en.wikipedia.org/wiki/Wrapper_pattern http://developerlife.com/tutorials/?p=19#Why http://en.wikipedia.org/wiki/Fa%C3%A7ade_pattern http://c2.com/cgi/wiki?AdapterPattern http://userpages.umbc.edu/~tarr/dp/lectures/Adapter-2pp.pdf