1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade 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

Framework is l Reusable Code, often domain specific (GUI, Net, Web, etc) l expressed as l a set of classes and l the way objects in those classes collaborate.
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
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,
Chapter 22 Object-Oriented Design
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.
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.
Department of Computer Science, York University Object Oriented Software Construction 13/10/ :44 AM 0 CSE3311 – Software Design Adapter Pattern.
The Adapter Pattern SE-2811 Dr. Mark L. Hornick 1.
GoF Sections Design Problems and Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
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.
SDP Structural Pattern. SDP-2 Structural Patterns Concerned with how classes and objects are composed to form large structures Class Patterns use.
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.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
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.
JAVA DESIGN PATTERN Structural Patterns - Facade Pattern Presented by: Amit kumar narela Ise Ise
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
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
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.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Object-Orientated Analysis, Design and Programming
Design Patterns: Brief Examples
Design Patterns Lecture part 2.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
By SmartBoard team Adapter pattern.
Adapter Design Pattern
Satisfying Open/Closed Principle
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
The Adapter Pattern.
10. Façade Pattern SE2811 Software Component Design
Adapter
A (partial) blueprint for dealing with change
Object-Oriented PHP (1)
Decorator Pattern.
Adapter Pattern Jim Fawcett
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

1 Dept. of Computer Science & Engineering, York University, Toronto CSE3311 Software Design Adapter Pattern Façade pattern

2 Being Adaptive  Or, how to perform the impossible feat of putting a square peg in a round hole

3 Design Problem 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

4 SHAPE vs. TEXT_VIEW  SHAPE assumes a bounding box defined by its opposing corners  TEXT_VIEW is defined by its origin, height and width.

5 Requirements  We would like to re-use TEXT_VIEW as a SHAPE  However, they have incompatible interfaces  How would you re-arrange the classes so that TEXT_VIEW can be treated as a shape?  Environmental constraint: We cannot change the interface or implementation of TEXT_VIEW

6 Design 1  Change the TEXT_VIEW class’s 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.  Recall the open-closed principle

7 Design 2  Recall the open-closed principle  Adapter Pattern

8 Non-software analogy  North American equipment electricity requirements: 110V, 60 Hz.  European electricity: 220V, 50 Hz.  Not practical to  Buy new equipment (computer, ipod etc) when traveling  Build a new electricity transmission system while in Europe  Solution  Use an adapter

9

10 How?

11 Client-supplier adaptor

12 TEXT_VIEW TEXT_SHAPE

13

14 Adapter – Context  You want to use an existing class (TEXT_VIEW) without modifying it  Adaptee  The context in which you want to use the class requires conformance to an interface that is different from that of the adaptee  Target (SHAPE)  The target interface and the adaptee interface are conceptually related

15 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

16 Inheritance Adapter

17 Two Kinds of Adapters  TEXT_SHAPE inherits SHAPE's interface and TEXT_VIEW's implementation.  Inheritance Adapter  TEXT_SHAPE2 inherits SHAPE's interface and uses TEXT_VIEW's implementation.  Client-Supplier Adapter (also mistakenly called object adapter)

18 Participants  Target (SHAPE)  defines the domain-specific interface that Client uses.  Client (DrawingEditor)  collaborates with objects conforming to the Target interface.  Adaptee (TEXT_VIEW)  defines an existing interface that needs adapting.  Adapter (TEXT_SHAPE)  adapts the interface of Adaptee to the Target interface.

19 Applicability  Use the Adapter pattern when  you want to use an existing class, and its interface does not match the one you need.  you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces.  (object adapter only) you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class.

20 Consequences  Class and object adapters have different trade-offs. A class adapter  adapts Adaptee to Target by committing to a concrete Adapter class. As a consequence, a class adapter won't work when we want to adapt a class and all its subclasses.  lets Adapter override some of Adaptee's behavior, since Adapter is a subclass of Adaptee.  introduces only one object, and no additional pointer indirection is needed to get to the adaptee.  An object adapter  lets 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.  makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.

21 Eiffel has rich adapter mechanisms  Rename  Redefine  Changing export status  OOSC2 chapter 15 (Multiple inheritance)  Undefine  Select

22 Adapter real-world examples  java.io.Reader is an abstract class for reading character streams [TARGET]  Contains an abstract method read(char[],int,int)  java.io.InputStream represents an input stream of bytes [ADAPTEE]  Contains method read(byte[],int,int)  java.io.InputStreamReader is an adapter from byte streams to character streams [ADAPTER]  Implements read(char[],int,int) using read(byte[],int,int)

23 Adapter Pattern Intent  Convert the interface of a class into another interface that clients expect.  Adapter lets classes with otherwise incompatible interfaces work together

24  And now for something different  another quick pattern

25  Turn on the popcorn popper  Start the popper popping  Dim the lights  Put the screen down  Turn projector on  Set projector input to DVD  set to wide screen  set amp to DVD in  set amp to suuround sound  set amp volume to med  start DVD  ……..

26

27

28  This principle prevents us from creating designs that have a large number of classes coupled together so that changes in one part of the system cascade to other parts. When you build a lot of dependencies between many classes, you are building a fragile system that will be costly to maintain and complex for others to understand.  See OOSC2 p46-53:  Every module should communicate with as few others as possible  If two modules communicate, they should exchange as little information as possible

29