Reuse at Design Level: Design Patterns

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

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

Design Patterns. An introduction

Object-Oriented Design

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

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

An Introduction to Patterns

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

Introduction and History

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

Design Patterns. Gunnar Gotshalks A4-1

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

Object-Oriented Oriented Programming

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

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. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

SDC Design patterns GoF

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

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Introduction to Software Engineering: Object Design I Reuse & Patterns

Topics in Object-Oriented Design Patterns

Software Engineering - I An Introduction to Software Construction Techniques for Industrial Strength Software

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

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

An Introduction to Patterns

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

Coordination Patterns

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Using Design Patterns in Java Application Development

Design Patterns in C++

3 Product Management Anti-Patterns by Thomas Schranz

DESIGN PATTERN - INTERVIEW QUESTIONS

CSE870: Advanced Software Engineering (Cheng) 1

What is Design Patterns?

Material and some slide content from: - GoF Design Patterns Book. Design Patterns #1. Reid Holmes. Lecture 11 - Tuesday October

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

Design patterns. OOD Lecture 6

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

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

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

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)

Design Patterns! Acknowledgements!

A Reconnaissance on Design Patterns

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

CS/CE 2336 Computer Science II

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

Review Software Engineering October, 7, Adrian Iftene

Design Patterns. Hausi A. Müller University of Victoria. Software Architecture Course Spring 2000

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

CSC7203 : Advanced Object Oriented Development. J Paul Gibson, D311. Design Patterns

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

Brief Note on Design Pattern

The GoF Design Patterns Reference

Tuesday, October 4. Announcements

Summary of the course lectures

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

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

Design Patterns IV Structural Design Patterns, 1

Adapter Pattern Structural

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

Design Patterns Reid Holmes

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

Foundations of Software Engineering Design Patterns -- Introduction

Object Oriented Paradigm

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

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

CHAPTER 6: CREATIONAL DESIGN PATTERNS

ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya

2.1 Design Patterns and Architecture (continued)

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

6.3 Patterns. Definition: Design Patterns

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

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

administrivia today UML start design patterns Tuesday, September 28, 2010

Second Midterm Review

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

Design Pattern and Software Architecture: IV. Design Pattern

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

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

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

The Strategy Pattern Design Principle: Design Principle: Design Principle:

2.1 Design Patterns and Architecture (continued)

SOFTWARE PATTERNS. Joseph Bonello

Lecture 20: Design Patterns II

Software Engineering I (02161)

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

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

Design Patterns. Definition of a Design Pattern

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

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

Crash course on design patterns

Inheritance. EEC 521: Software Engineering. Dealing with Change. Polymorphism. Software Design. Changing requirements Code needs to be flexible

What is Design Patterns?

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

What is Design Patterns?

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

Information systems modelling UML and service description languages

Transcription:

Reuse at Design Level: Design Patterns CS 617- Lecture 17 Mon. 17 March 2008 3:30-5:00 pm Rushikesh K. Joshi Department of Computer Sc. & Engg. Indian Institute of Technology, Bombay Mumbai - 400 076

Reuse in Software Engineering Reuse at code level is common in software development e.g. C standard libraries such as math.h and stdio.h; user defined libraries such as serverutils, library.h What about reusing old design solutions and not just the code?

Christopher Alexander s Work Two books for building architects The timeless way of building: Alexander 1977 A Pattern language: Alexander et al. 1977 He classified the problems that occurred again and again and described core solutions to them that could be used again and again Examples: main entrance, sequence of sitting spaces, public outdoor room, interior windows

Patterns in Software Engineering Studies in other disciplines is helpful in software engineering other than computer science, its basic discipline Researchers in Object Oriented Software Engineering now find that design patterns can be formulated to represent commonly occurring problems in design and also the solutions to them

Framework Cookbooks Frameworks such as Smalltalk s MVC were available in 80 s But using a framework for a specific application needed the knowledge of classes and class interactions in the framework e.g Krasner and Pope s cookbook on MVC framework (1988) e.g. Ralph Johnson s cookbook: HotDraw for implementing graphical editor (1992)

The Growth of Pattern Community Gamma described patterns in ET++ framework in his Ph.D. thesis in 1992 Peter Code published an article on design patterns in an issue of CACM in 1992 Code organized OOPSLA workshops on patterns in 1992 and 1993 The pioneering book on design patterns by the gang of four Since then patterns have been discussed widely in the OO Software community

A Problem In a graphical editor, by clicking on an object, one can obtain a copy of the original object. Obtaining a copy of an existing object is a common design problem in on-line compositions. We can provide a design solution to solve this problem, and reuse this design whenever similar situation arises.

The Solution Client operation () proto ShapePrototype clone () proto-->clone() CirclePrototype clone () RectanglePrototype clone () copy of self copy of self

The Design Pattern: Prototype Client operation () proto Prototype clone () proto-->clone() ConcretePrototype1 clone () ConcretePrototype2 clone () copyof self copy of self

Describing a Design Pattern Specify the generic problem that is solved Motivate the design pattern solution with the help of an example Provide the structure for the pattern Discuss collaborations between classes Discuss other issues related to the pattern such as trade-offs, implementation techniques etc.

Template provided by Erich Gamma et. al Pattern name, its classification Intent, Motivation, Applicability Structure, Participants, Collaborations Consequences, Implementation, Sample code, Known uses Related patterns

Classification of Patterns Creational Patterns concerned about ways to create new objects Structural Patterns concerned about the composition of objects and classes Behavioral Patterns concerned about ways in which objects interact

Creational Patterns Singleton To create a sole instance of a class Prototype To create objects by cloning existing objects Builder build an object from existing representation

Creational Patterns Factory Method defer instantiation to subclasses Abstract Factory Provides interface to create families of objects without specifying the concrete classes of the objects

Singleton A class that creates only one instance at most Singleton static getsoleinstance() operation () static soleinstance..return soleinstance

Implementing Singleton Make the constructor protected Prohibit normal creation mode A new instance can only be created through a class method The class method is the static method in our case Return the unique instance crated

Singleton.c Class Singleton { protected: Singleton () ; public: static Singleton *getsoleinstance () {.}; private: static Singleton *soleinstance; }

Factory Method Example: In a modeling tool, you can select a type of entity or relation and then create an actual entity of the selected type. The selected icon thus acts as a factory or creator of some actual type. An object is used to create another One creator object creates instances of one class Hierarchy of creators, polymorphism on creation

An Example of Factory Method Primitive PrimIcon createprimitive () Relation Box create BoxIcon RelationIcon createprimitive() createprimitive() Return new Box

The Factory Method Pattern Product Creator factorymethod() concreteproduct ConcreteFactory factorymethod() Return new ConcreteProduct

Structural Patterns Adapter convert an interface to another Composite Compose objects in a tree structure Decorator Attach additional Responsibilities dynamically

More Structural Patterns Proxy Provide a surrogate or placeholder for another object Facade Provide a unified interface to a set of interfaces in a subsystem Bridge Decouple abstraction from implementation, let them vary independently

Adapter Pattern You are building a collection class hierarchy for collections such as FIFO, Set, LIFO You find that there is an existing class Stack which can be used for providing LIFO collection How do we adapt the existing class to the new interface of Collection classes?

The Solution Client Collection insert () fetch () Stack push() pop () FIFO insert () fetch () LIFO insert () fetch () pop ()

The Adapter Pattern Class Adapter Client Target request () Adaptee specificreq () Adapter request () specificreq()

The Adapter Pattern Object Adapter Client Target request () Adaptee specificreq () Adapter adaptee request () adaptee->specifireq()

Composite Pattern An Example: A Graphic Document is composed of graphical objects such as Line, Rectangle, Circle, Text, Image or another Graphical Document Thus a graphic document is a tree structured composition

The Solution Client GraphicElement draw () add ().. Circle draw () Line draw () GraphicDoc draw() add (..) GEs For all g in GEs g->draw()

Instance of a Composite Class mypicture haspicture asquare atext aline arectangle

The Composite Pattern Client Component operation () children aleaf operation () Composite operation() add (..) For all c in children c->operation()

components within a subsystem? Study the following scenario

The Facade Pattern Provide a unified interface for a subsystem Facade

A Paradigm for Remoting Distribution transparency - Client unaware of the distributed nature of the server Location Transparency - Client unaware of the location of the server A client invokes methods on an object as if it is a local object Proxy Handles provide a mechanism to implement this paradigm

Designing Surrogate Objects ClientProg Account deposit () RealAccount deposit () remoteacc AccountProxy deposit () remoteacc->deposit

The Proxy Pattern Client subject operation () RealSubject operation () realsubj Proxy operation() realsubj->operation

The Proxy Both real and proxy objects inherit from an abstract superclass Thus, they both provide the same interface Their implementations are different A client can handle anyone of them through generalization, i.e. a superclass pointer Internally proxy carries out the communication with the remote object

The Pattern Client has a pointer to the Subject Subject is the abstract superclass RealSubject is the server implementation Proxy is the proxy implementation available at the client process Proxy has a handle to RealSubject operation() is implementation differently by RealSubject and Proxy classes

The Decorator: Object Diagram client borderdecorator component scrolldecorator component textview

Visualcomponent draw () TextView Decorator component operation () draw() Component->draw() Scroller draw () drawscroller Border draw() drawborder() Decorator::draw() drawborder()

References [1] E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns, Addison-Wesley, 1995 [2] W. Pree, Design Patterns for Object-Oriented Development, Addison-Wesley, 1995 [3] Linda Rising, The Patterns Handbook, Cambridge University Press, 1998