Adapter Pattern Structural

Similar documents
ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya

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

Object-Oriented Oriented Programming Adapter Pattern

Design Patterns IV Structural Design Patterns, 1

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

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

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

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

Design Patterns. GoF design patterns catalog

Design Patterns in C++

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

Design Patterns Revisited

Lecture 13: Design Patterns

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

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

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

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

Design Patterns in Python (Part 2)

Object-Oriented Concepts and Design Principles

Foundations of Software Engineering Structural Design Patterns

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

Reuse at Design Level: Design Patterns

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

Design Patterns Reid Holmes

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

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

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

Design Patterns! Acknowledgements!

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

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

Design Patterns. Definition of a Design Pattern

Design Patterns V Structural Design Patterns, 2

Design Pattern: Composite

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

INTERNAL ASSESSMENT TEST III Answer Schema

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

Software Engineering

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

SDC Design patterns GoF

Topics in Object-Oriented Design Patterns

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

CSE870: Advanced Software Engineering (Cheng) 1

Design Pattern Detection

» Access elements of a container sequentially without exposing the underlying representation

SOFTWARE PATTERNS. Joseph Bonello

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

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

Software Eningeering. Lecture 9 Design Patterns 2

Design Patterns Lecture 2

CISC 322 Software Architecture

Design Pattern Detection

Lecture 20: Design Patterns II

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

Design for change. You should avoid

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

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

COURSE 4 DESIGN PATTERNS

Component ConcreateComponent Decorator ConcreateDecoratorA ConcreteDecoratorB

CS 520 Theory and Practice of Software Engineering Fall 2018

Design Patterns. An introduction

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

ADTs. An ADT module is a module that exports a type, along with the operations needed to access and manipulate objects of that type.

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

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

Design Patterns and Frameworks Command

A Reconnaissance on Design Patterns

CS 170 Java Programming 1. Week 15: Interfaces and Exceptions

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

The Decorator Pattern. Design Patterns In Java Bob Tarr

CS 520 Theory and Practice of Software Engineering Fall 2017

18.1 Definitions and General OO Principles

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

UNIT I Introduction to Design Patterns

Design Patterns Reid Holmes

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

What is a Pattern? Lecture 40: Design Patterns. Elements of Design Patterns. What are design patterns?

Design Patterns. On Design Patterns. Becoming a Master Designer. Patterns & Frameworks

DESIGN PATTERN - INTERVIEW QUESTIONS

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Template Method Pattern. George Blankenship

Using Design Patterns in Java Application Development

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

Software Quality Management

Coordination Patterns

Department of Information Technology

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

Event Handling Java 7

The GoF Design Patterns Reference

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

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship

CS 2340 Objects and Design

K.Yellaswamy Assistant Professor CMR College of Engineering & Technology

Overview of Java s Support for Polymorphism

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

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

Chapter 8, Design Patterns Visitor

Unit Wise Questions. Unit-1 Concepts

Inheritance. Transitivity

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

CMSC 132: Object-Oriented Programming II

Transcription:

Adapter Pattern Structural Intent» Convert the interface of a class into a different interface that a client expects.» Lets classes work together that otherwise could not Adapter-1

Class Adapter Motivation EDITOR expects a SHAPE TEXT_VIEW is not a SHAPE TEXT_SHAPE is a SHAPE Reuse TEXT_VIEW in the context of a SHAPE SHAPE shape[ ] EDITOR FIGURE_SHAPE TEXT_SHAPE TEXT_VIEW Adapter-2

Object Adapter Motivation EDITOR expects a SHAPE TEXT_VIEW is not a SHAPE TEXT_SHAPE is a SHAPE Reuse subclasses of TEXT_VIEW in the context of a SHAPE SHAPE shape[ ] EDITOR FIGURE_SHAPE TEXT_SHAPE text TEXT_A TEXT_VIEW TEXT_B Adapter-3

Applicability Use an existing class when its interface does not match the one you need Create a class that cooperates with unrelated or unforeseen classes with incompatible interfaces Object Adapter Only Need to use several existing subclasses, but it is impractical to adapt by sub-classing each one of them Object adapter adapts the interface of the parent class Adapter-4

Participants TARGET Application interface Client Target user Adaptee Interface that needs adapting TARGET ADAPTER CLIENT ADAPTEE Adapter alternative name wrapper Provides functionality not provided by the adaptee Either relationship (only 1 of them for an ADAPTER) is_a class adapter has_a object adapter Adapter-5

Object Adapter Scenario TARGET CLIENT ADAPTEE Scenario collaboration 1 Client does target.method_in_target 2 Adapter does adaptee.method_in_adaptee (note polymorphism) ADAPTER adaptee : ADAPTEE method_in_target CLIENT 1 TARGET 2 ADAPTEE Adapter-6

Object Adapter Pseudocode class ADAPTER feature adaptee : ADAPTEE... method_in_target do pre_actions adaptee. method_in_adaptee post_actions end end end class ADAPTEE feature method_in_adaptee do... end end end Adapter-7

Object Adapter Stack Implementation The Adapter pattern used where stack operations are calls to "equivalent" sequence operations Sequence container; Push Uses the Sequence puthead public void push(final Object obj) { container.puthead(obj); } Pop Uses the Sequence takehead public Object pop() { return container.takehead(); } Adapter-8

Consequences There are tradeoffs a class adapter inheritance» adapts Adaptee to Target by committing to concrete Adapter class Class adapter is not useful when we want to adapt a class and all its subclasses» Lets Adapter override some of Adaptee's behaviour Adapter is a subclass of Adaptee» Introduces only one object No additional pointer indirection is needed to get to adaptee Adapter-9

Consequences 2 There are tradeoffs an object adapter uses» One Adapter can work with many Adaptees > Adaptee and all its subclasses > Can add functionality to all Adaptees at once» Makes it harder to override Adaptee behaviour Or Requires making ADAPTER refer to the subclass rather than the ADAPTEE itself Subclassing ADAPTER for each ADAPTEE subclass Adapter-10

Related Patterns Bridge is similar to object Adapter but Bridge is meant to separate interface from implementation so they can vary independently, while Adapter extends the interface of an existing object Decorator is more transparent than Adapter, so Decorator supports recursive composition, while Adapter doesn't Proxy defines a representative for another object and does not change its interface Adapter-11

Adapter in Java API Java Listeners are adapters.» mymethod in myclass is to execute whenever mybutton is pressed» Introduce MyListener that implements the ActionListener class > MyListener is an adapter as the program text in mybutton references ActionListener Adapter-12