Adapter Design 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

1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Inheritance Inheritance Reserved word protected Reserved word super
Inheritance. 2 The process of deriving new class from the existing one is called inheritance Then the old class is called base class and the new class.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
1 Inheritance Inheritance is a natural way to model the world in object-oriented programming. It is used when you have two types of objects where one is.
ADAPTER PATTERN Ali Zonoozi Design patterns course Advisor: Dr. Noorhoseini Winter 2010.
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.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
Chapter 10 Classes Continued
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Inheritance using Java
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
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.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Inheritance in the Java programming language J. W. Rider.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
Coming up: Inheritance
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Topics Inheritance introduction
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
1 Inheritance Inheritance is a natural way to model the world in object-oriented programming. It is used when you have two types of objects where one is.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Inheritance Class Hierarchies SoftUni Team Technical Trainers Software University
Advanced Programming in Java
Advanced Programming in Java
Design Patterns Spring 2017.
Advanced Java Topics Chapter 9
Chapter 10 Design Patterns.
By SmartBoard team Adapter pattern.
Creational Pattern: Prototype
Inheritance What is inheritance?
Object-Oriented Programming
Factory Method, Abstract Factory, and More
Object Oriented Analysis and Design
Object Oriented Practices
Adapter Pattern 1.
Lecture 22 Inheritance Richard Gesick.
Advanced Java Topics Chapter 9
Advanced Programming Behnam Hatami Fall 2017.
Code reuse through subtyping
Review: Design Pattern Structure
Advanced Programming in Java
Object Oriented Practices
Advanced Programming in Java
SE2811 Software Component Design Dr. Rob Hasker
Structural Patterns: Adapter and Bridge
The Adapter Pattern.
SE2811 Software Component Design Dr. Rob Hasker
Object Oriented Analysis and Design
Adapter Pattern Jim Fawcett
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
The Object Paradigm Classes – Templates for creating objects
Computer Science II for Majors
Adapter Pattern Jim Fawcett
Presentation transcript:

Adapter Design Pattern Modifying Existing Interfaces

Access Methods Revisited base class features: public protected private access modifiers derived class features public: public protected inaccessible protected: protected protected inaccessible private: private private inaccessible public inheritance – allows to inherit the interface: is-a relationship abstract functions of base class – only interface concrete functions of base class – both interface and implementation private inheritance – allows to inherit implementation, interface is not inherited (by default): implemented-in-terms-of relationship features may be added to interface with using

Making Private Feature Pubic If inheriting a private base class feature, it may be made public by stating this in public portion of derived class definition: using BaseClass::BaseClassFeature; example: Class Figure{ public: int findCenter(); }; class Square: private Figure{ using Figure::findCenter; client code: Square small; small.findCenter();

Multiple Inheritance may need to inherit from multiple classes: toy car: has features of a toy and a car different access methods possible example: class C needs to inherit interface from class A and implementation from class B: class C: public A, private B {…}; what would be access methods for toy car?

Adapter Design Pattern if have interface class and an implementation class with incompatible interface why not change implementation? it might be okay as it is (used elsewhere) may take effort, rather reuse code as is adapter (wrapper) - concrete class that inherits from interface adaptee – implementation class whose interface is modified (adapted) two approaches class adapter – uses multiple inheritance object adapter – uses delegation from adapter to adaptee structural design pattern

Class Adapter Adapter (publicly) inherits interface from Target and (privately) implementation from Adaptee

Object Adapter Adapter uses aggregation to delegate requests to Adaptee

Difference between Adapter and Bridge patterns look similar difference is in usage bridge: build new class hierarchy adapter: modify existing classes to particular use

Adapter Review what is the major difference between public and private inheritance in access methods of class members? in usage? what is the motivation for Adapter use? what is adapter (wrapper) ? adaptee? how does Class Adapter use multiple inheritance to accomplish the task? how does Object Adapter use delegation to accomplish the task? what is the difference between Adapter and Bridge?