Object-Oriented Oriented Programming Adapter Pattern. CSIE Department, NTUT Woei-Kae Chen

Similar documents
Object-Oriented Oriented Programming Adapter Pattern

ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya

Adapter Pattern Structural

Design Patterns IV Structural Design Patterns, 1

COSC 3351 Software Design. Design Patterns Structural Patterns (I)

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns

Design Patterns. GoF design patterns catalog

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Object-Oriented Oriented Programming Command Pattern. CSIE Department, NTUT Woei-Kae Chen

Object-Oriented Oriented Programming

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

CISC 322 Software Architecture

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

State Pattern. CSIE Department, NTUT Woei-Kae Chen. State: Intent. Allow an object to alter its behavior when its internal state changes.

Lecture 13: Design Patterns

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

Design Patterns! Acknowledgements!

INTERNAL ASSESSMENT TEST III Answer Schema

Adapter & Facade. CS356 Object-Oriented Design and Programming November 19, 2014

Foundations of Software Engineering Structural Design Patterns

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Design Patterns in C++

Design Patterns. Definition of a Design Pattern

SDC Design patterns GoF

Design Patterns Reid Holmes

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Object-Oriented Oriented Programming Factory Method Pattern Abstract Factory Pattern. CSIE Department, NTUT Woei-Kae Chen

Design Patterns Revisited

Factory Method Pattern Creational. » Define an interface for creating an object but lets subclasses decide the specific class to instantiate

Design Pattern: Composite

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Patterns V Structural Design Patterns, 2

2/17/04 Doc 8 Adapter & Strategy slide # 1

Design for change. You should avoid

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

EECS 4314 Advanced Software Engineering. Topic 04: Design Pattern Review Zhen Ming (Jack) Jiang

Design Patterns in Python (Part 2)

COURSE 4 DESIGN PATTERNS

Reuse at Design Level: Design Patterns

CSE870: Advanced Software Engineering (Cheng) 1

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

Design Pattern Detection

Software Engineering

Software Eningeering. Lecture 9 Design Patterns 2

JUnit: The Goals of JUnit

Last Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005

Design Patterns Lecture 2

Topics in Object-Oriented Design Patterns

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Design Pattern Detection

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

CS 2340 Objects and Design

INSTITUTE OF AERONAUTICAL ENGINEERING

Using Design Patterns in Java Application Development

UNIT I Introduction to Design Patterns

Lecture 20: Design Patterns II

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Chapter 8, Design Patterns Visitor

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Coordination Patterns

Object-Oriented Oriented Programming

Creational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU)

Tecniche di Progettazione: Design Patterns

UNIT I Introduction to Design Patterns

Design Patterns. An introduction

Review of last class. 1.Class inheritance versus interface inheritance 2.Inheritance versus composition. Dr. Xiaolin Hu

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

L23.1 Introduction... 2

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

Object-Oriented Concepts and Design Principles

Last Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns

Programmazione. Prof. Marco Bertini

SOFTWARE PATTERNS. Joseph Bonello

Design Patterns Reid Holmes

Object Oriented. Analysis and Design

Review -- an Exercise. Use the Elevator example as a context, develop a: Use case diagram Class diagram Sequence diagram Start Chart diagram

DESIGN PATTERNS Course 4

The GoF Design Patterns Reference

The Decorator Pattern. Design Patterns In Java Bob Tarr

LECTURE NOTES ON DESIGN PATTERNS MCA III YEAR, V SEMESTER (JNTUA-R09)

Design Patterns B. Reid Holmes. Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book

Prototype Pattern Creational

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns

DESIGN PATTERN MATCHING

Component ConcreateComponent Decorator ConcreateDecoratorA ConcreteDecoratorB

Department of Information Technology

CHAIN OF RESPONSIBILITY (DP 223)

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Foundations of Software Engineering Design Patterns -- Introduction

Prototype Pattern Creational

Adapter. Comp-304 : Adapter Lecture 23. Alexandre Denault Computer Science McGill University Fall 2007

Transcription:

Object-Oriented Oriented Programming Adapter Pattern CSIE Department, NTUT Woei-Kae Chen

Adapter: Intent Convert the interface of a class into another interface clients expect. Adapter lets classes work together that could not otherwise because of incompatible interfaces. Also known as Wrapper

Adapter: Motivation DrawingEditor Shape BoundingBox() Adaptee TextView GetExtend() Client CreateManipulator() Adapter Target Line BoundingBox() CreateManipulator() TextShape BoundingBox() CreateManipulator() New functionality return text->getextent() return new TextManipulator The adapter is responsible for functionality the adapted class does not provide.

Adapter: Applicability You want to use an existing class, and its interface does not match the one you need. You want to create a class that cooperates with unrelated or unforeseen classes incompatible interfaces. Object adapter only You need to use several existing subclasses, but it s impractical to adapt their interface by subclassing every one. adapt the interface of its parent class

Adapter: Structure (1) Class adapter: use multiple inheritance Client Target Request() Adaptee SpecificRequest() (implementation) C++ private inheritance Adapter Request() SpecificRequest()

Adapter: Structure (2) Object adapter: use object composition Client Target Request() Adaptee SpecificRequest() Adapter Request() adaptee adaptee->specificrequest()

Adapter: Participants Client (Drawing Editor) collaborates with objects conforming to the Target interface. Target (Shape) defines the domain-specific interface that Client uses. Adapter (TextShape) adapts the interface of Adaptee to the Target interface Adaptee (TextView) defines an existing interface that needs adapting.

Adapter: Collaboration Clients call operations on an Adapter instance. In turn, the adapter calls Adaptee operations that carry out the request.

Adapter: Consequences (1) Class adapter Object adapter Class adapter adapts Adaptee to Target by committing to a concrete Adaptee class doesn't work when adapting a class and all its subclasses. allow Adapter to override some of Adaptee s behavior introduces only one object no additional pointer indirection is needed to get to the adaptee. Object adapter a single Adapter works with many Adaptees (Adaptees and all of its subclasses; add functionality to all Adaptees at once. harder to override Adaptee behavior.

Adapter: Consequences (2) How much adapting does Adapter do? Adapters vary in the amount of work they do to adapt Adaptee to the Target interface. Pluggable adapters classes with build-in interface adaptation. Two-way adapters (provide transparency) an adapted object no longer confirms to the Adaptee interface can t be used as an Adaptee object. useful when two different clients need to view an object differently.

Adapter: Consequences (3) Two-way adapter using multiple inherence (to QOCA hierarchy) (to Unidraw class hierarchy) ConstraintVaribale StateVariable ConstraintStateVariable

Adapter: Implementation (1) Class adapter in C++ public from Target and private from Adaptee. Pluggable adapters classes with build-in interface adaptation. narrow interface: the smallest subset of operations for adaptation. three implementation approaches Using abstract operations Using delegate objects Parameterized adapters supports adaptation without subclassing Smalltalk: block construct; Java: reflection

Adapter: Implementation (2) Pluggable adapter: using abstract operations to simply XXXTreeDisplay TreeDisplay GetChildren(Node) CreateGraphicNode(Node) Display() BuildTree(Node n) Client, Target Adapter DirectoryTreeDisplay GetChildren(Node) CreateGraphicNode(Node) Narrow interface Template Method GetChildren(n) for each child { AddGraphicNode( CreateGraphicNode(child) ) BuildTree(child) } FileSystemEntity Adaptee

Client Adapter: Implementation (3) Pluggable adapter: using delegate objects TreeDisplay SetDelegate(Delegate) Display() BuildTree(Node n) to simply XXXBrowser delegate TreeAccessorDelegate GetChildren(TreeDisplay,Node) Target CreateGraphicNode(TreeDisplay,Node) Strategy Adapter delegate->getchildren(this,n) for each child { AddGraphicNode( delegatep-> CreateGraphicNode(child) ) BuildTree(child) } DirectoryBrowser GetChildren(TreeDisplay, Node) CreateGraphicNode(TreeDisplay,Node) CreateFile() DeleteFile() FileSystemEntity Adaptee

Adapter: Related patterns Bridge Bridge has a structure similar to an object adaptor different intents. Decorator Decorator enhances another object without changing its interface more transparent than an adapter. Proxy Proxy defines a surrogate for another object without changing its interface. Template Method Can be used to implement pluggable adapter. Strategy Can be used to implement pluggable adapter