More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.

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

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Object-Oriented PHP (1)
Chapter 8, Object Design Introduction to Design Patterns
March R McFadyen1 Façade. March R McFadyen2 Facade P Main Entry: fa·cade Variant(s): also fa·çade / f&-'säd/ Function: noun.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns Ric Holt & Sarah Nadi U Waterloo, March 2010.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Façade Design Pattern (1) –A structural design pattern.
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Design Patterns.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
SOFTWARE DESIGN AND ARCHITECTURE
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Y2 eProjects Session 4 – Advanced Topics. Objectives  Dynamic Models  Design Patterns (Optional)  Software testing (for S4) ACCP i7.1\Sem3_4\eProject\T4.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
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.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
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.
CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
CS 4240: Rethinking Some OOP Ideas and Terms for OOA&D Readings: Chap. 8 in Shalloway and Trott (referred to as S&T in these slides) Wikipedia on information.
Adapter and Façade Patterns By Wode Ni and Leonard Bacon-Shone.
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:
More Patterns CS 124. More Basic Patterns Patterns you’ve already seen (without knowing it) Observer / Listener Wrapper Composite Decorator / Filter Patterns.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Chapter Eight Expanding Our Horizons Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering.
Chapter Ten The Bridge Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
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.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
CS 350 – Software Design The Facade Pattern – Chapter 6 Many design patterns are catalogued in the “Gang of Four” text. I find their definitions not to.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns – Group 2 Iterator, Proxy, Adapter, Decorator.
Presented by FACADE PATTERN
Design Patterns: MORE Examples
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Chapter Six The Facade Pattern
By SmartBoard team Adapter pattern.
Introduction to Design Patterns
CS 350 – Software Design The Facade Pattern – Chapter 6
Facade From Main Entry: fa·cade Variant(s): also fa·çade /f&-'säd/ Function: noun Etymology: French façade, from Italian facciata,
Object Oriented Analysis and Design
Advanced Programming Behnam Hatami Fall 2017.
Object Oriented Design Patterns - Structural Patterns
CS 350 – Software Design Principles and Strategies – Chapter 14
Lecture taken from “Design Patterns Explained” by Addison Wesley
Adapter Design Pattern
The Adapter Pattern.
Object Oriented Analysis and Design
Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
C++ Object Oriented 1.
Presentation transcript:

More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.

Design Patterns Why study design patterns? –Reuse solutions – can learn from the experts –Establish common terminology – design patterns provide a common point of reference during analysis and design Patterns provide a higher-level perspective on the problem and on design See Parnas quote, Brooks p. 221 See also Brooks pp. 224, 225 on “Learning Large Vocabularies”

Design Patterns Big picture strategies for creating good object-oriented designs (Gang of Four) –Design to interfaces –Favor aggregation (composition) over inheritance (generalization) –Find what varies and encapsulate it

Façade Pattern Intent: “To provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.” (Gang of Four, p. 185)

Façade Pattern Idea: Enables one to use a complex system more easily, either –To use just a subset of the system, or –To use the system in a particular way

Façade Pattern Example: Suppose I have a Client object that must open a Database to get a Model, then query the Model to get an Element, and finally ask Element for information It is much easier to create a DatabaseFacade that can be queried by the Client

Façade Pattern Variation on Façade: –In addition to using functions in the system one could add new functionality, e.g. log all calls to specific routines Idea of Façade pattern with expanded functionality Façade pattern – I am creating a new interface for the client to use instead of the existing system’s interface

Façade Pattern Façade can also be used to hide, or encapsulate, the system => the Façade object could contain the system as private members Benefits of encapsulating system: –Track system usage –Swap out systems – only have to change code in one place – the Façade

Adapter Pattern Intent: “Convert the interface of a class into another interface that the clients expect. Adapter lets classes work together that could not otherwise because of incompatible interfaces.” (Gang of Four, p. 139) Idea: Need to create a new interface for an object that does the right thing but has the wrong interface

Adapter Pattern Example: Suppose I create classes for points, lines, square that have the behavior “display” Client should not have to know whether they actually have a point, a line, a square. They just want to know that they have one of these shapes

Adapter Pattern Example (cont): Using polymorphism there will be different types of objects but the clients interact with them in a common way Define an interface (in this case the abstract class Shape) from which the other classes are derived

Adapter Pattern

Now suppose I need to implement a circle – a new kind of Shape So I create a new class Circle that extends Shape and I need to code display, fill, undisplay However, I find that another programmer has already written a class XXCircle that does what I want except the names of the methods aren’t what I require

Adapter Pattern XXCircle has methods: displayIt, fillIt, undisplayIt Two reasons I cannot directly use XXCircle: –I have different names and parameter lists –It does not extend Shape

Adapter Pattern Rather than change XXCircle I adapt it I make a new class Circle: –Circle extends Shape –Circle contains XXCircle –Circle passes messages through (“delegates”) to the XXCircle object

Adapter Pattern

Adapter pattern enabled me to continue to use polymorphism with Shape

Adapter Pattern

Variations – there are two types of Adapter patterns: –Object Adapter pattern – one object (adapting object) contains another object (adapted object) –Class Adapter pattern – using multiple inheritance the adapter class Derives publicly from the abstract class to define its interface Derives privately from existing class to access its implementation

Comparing Adapter with Façade Both Adapter and Façade are “object wrappers” – wrapping an existing interface with a new interface FaçadeAdapter Are there pre-existing classes?Yes Is there an interface we must design to? NoYes Does an object need to behave polymorphically? NoProbably Is a simpler interface needed?YesNo

Comparing Adapter with Façade Bottom line: A Façade simplifies an interface while an Adapter converts a pre-existing interface into another interface (usually in the context of polymorphism).

Object-Oriented Design: A New Perspective Object Traditional view: object = data with methods New view: object = entity that has responsibilities Responsibilities define the behavior of the object

Object-Oriented Design: A New Perspective Better definition since focus is on what objects are supposed to do not on how they are implemented Recurring theme of design patterns: Focus on motivation rather than on implementation

Object-Oriented Design: A New Perspective Encapsulation Traditional view: Encapsulation = data hiding New view: Encapsulation = any kind of hiding

Object-Oriented Design: A New Perspective Encapsulation – can hide –Implementations –Derived classes –Design details –Instantiation rules

Object-Oriented Design: A New Perspective Examples of encapsulation: Encapsulation of data – the data in Point, Line, Square, Circle are hidden from everything else Encapsulation of methods – e.g. Circle’s setLocation Encapsulation of other objects – Nothing but Circle is aware of XXCircle Encapsulation of type – Clients of Shape know nothing of Point, Line, Square, Circle

Object-Oriented Design: A New Perspective