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

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

Design Patterns. An introduction

Using Design Patterns in Java Application Development

Design Patterns. Gunnar Gotshalks A4-1

CS/CE 2336 Computer Science II

Applying the Observer Design Pattern

SDC Design patterns GoF

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

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

Applying the Decorator Design Pattern

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

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

Object-Oriented Design

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

Object-Oriented Design

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

Applying the Factory Method Design Pattern

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

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

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

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

CS251 Software Engineering Lectures 18: Intro to DP

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

What is Design Patterns?

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

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

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

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

DESIGN PATTERN - INTERVIEW QUESTIONS

Tuesday, October 4. Announcements

A Rapid Overview of UML

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

Introduction and History

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

Object-oriented Software Design Patterns

Object-Oriented Oriented Programming

3 Product Management Anti-Patterns by Thomas Schranz

A Reconnaissance on Design Patterns

Review Software Engineering October, 7, Adrian Iftene

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

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

What is Design Patterns?

An Introduction to Patterns

The GoF Design Patterns Reference

UNIT I Introduction to Design Patterns

Software Engineering I (02161)

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

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

Introduction to Software Engineering: Object Design I Reuse & Patterns

Chapter 12 (revised by JAS)

Design Patterns. "Gang of Four"* Design Patterns. "Gang of Four" Design Patterns. Design Pattern. CS 247: Software Engineering Principles

CS 247: Software Engineering Principles. Design Patterns

Topics in Object-Oriented Design Patterns

Crash course on design patterns

Foundations of Software Engineering Design Patterns -- Introduction

INSTITUTE OF AERONAUTICAL ENGINEERING

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

SOLID DESIGN PATTERNS FOR MERE MORTALS

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

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

UNIT I Introduction to Design Patterns

1 Software Architecture

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

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

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Design patterns. OOD Lecture 6

An Introduction to Patterns

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Why a Design Pattern. History of Design Pattern. Properties

Design Pattern and Software Architecture: IV. Design Pattern

What is Design Patterns?

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

Application Architectures, Design Patterns

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

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

DESIGN PATTERNS FOR MERE MORTALS

Software Design COSC 4353/6353 D R. R A J S I N G H

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Design Patterns Reid Holmes

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Object Oriented Programming. Michał Bereta

Ingegneria del Software Corso di Laurea in Informatica per il Management. Software quality and Object Oriented Principles

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

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

2.1 Design Patterns and Architecture (continued)

Applying Design Patterns to SCA Implementations

Extensibility Design Patterns From The Initial Stage of Application Life-Cycle

Coordination Patterns

WS01/02 - Design Pattern and Software Architecture

Kerievsky_book.fm Page 355 Thursday, July 8, :12 PM. Index

Overview of Patterns: Introduction

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

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

6.3 Patterns. Definition: Design Patterns

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

CHAPTER 6: CREATIONAL DESIGN PATTERNS

2.1 Design Patterns and Architecture (continued)

Nat. Thomas Software Engineering Telephonics Inc. Long Island IEEE Lecture Series

Transcription:

Ingegneria del Software Corso di Laurea in Informatica per il Management Design Patterns part 1 Davide Rossi Dipartimento di Informatica Università di Bologna

Pattern Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice [Alexander 77]

Design Pattern Patterns provide workable solutions to all of the problems known to arise in the course of design. [Beck, Cunningham - 87] A named description of a problem, solution, when to apply the solution, and how to apply the solution in new contexts. [Larman] A general reusable solution to a commonly occurring problem within a given context in software design [wikipedia]

Languages and catalogs Patterns are usually grouped into a coherent structure with its own vocabulary, syntax (context) and grammar (use). Patterns are linked so the adoption of one suggests other to consider.

Patterns catalogs The are several existing catalogs for patterns in software engineering. We will focus on design patterns. There are several existing catalogs for design patterns too. We will present design patterns from Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides (the Gang of Four) - 1994.

Documentation Pattern Name and Classification: A descriptive and unique name that helps in identifying and referring to the pattern. Intent: A description of the goal behind the pattern and the reason for using it. Also Known As: Other names for the pattern. Motivation (Forces): A scenario consisting of a problem and a context in which this pattern can be used.

Documentation Applicability: Situations in which this pattern is usable; the context for the pattern. Structure: A graphical representation of the pattern. Class diagrams and Interaction diagrams may be used for this purpose. Participants: A listing of the classes and objects used in the pattern and their roles in the design. Collaboration: A description of how classes and objects used in the pattern interact with each other.

Documentation Consequences: A description of the results, side effects, and trade offs caused by using the pattern. Implementation: A description of an implementation of the pattern; the solution part of the pattern. Sample Code: An illustration of how the pattern can be used in a programming language. Known Uses: Examples of real usages of the pattern. Related Patterns: Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns.

GoF patterns purposes Creational abstract the instantiation process Structural are concerned with how classes and objects are composed to form larger structures Behavioral are concerned with algorithms and the assignment of responsibilities between objects

The 23 Creational: Abstract Factory, Builder, Factory Method, Prototype, Singleton Structural: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy Behavioral: Chain of responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template method, Visitor

GoF: Template Method Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

Template Method

Template Method java.util.abstractlist<e> { int indexof(object o) abstract E get(int index) }

Template Method Moves common behaviors up in the inheritance tree even when partially specified New implementations of the abstract superclass do not break clients: dependencies are directed to more stable elements Helps adherence to OCP

What s wrong with inheritance? Vehicle Car Aircraft Drone

What s wrong with inheritance? Vehicle Car Aircraft Drone Vehicle goto() Car Aircraft Drone goto() {drive} goto() {flight} goto() {flight}

What s wrong with inheritance? goto in Aircraft and in Drone behave in the same manner Needless Repetition (from design smells) Copy and paste may be useful text-editing operations, but they can be disastrous code-editing operations. When the same code appears over and over again, in slightly different forms, the developers are missing an abstraction.

What s wrong with inheritance? Vehicle goto() Car FlyingVehicle goto() {drive} goto() {flight} Aircraft Drone

What s wrong with inheritance? Vehicle goto() notifydriver() Car FlyingVehicle goto() {drive} goto() {flight} Aircraft Drone

What s wrong with inheritance? What s wrong with our use of inheritance? We are not addressing OCP correctly We are not addressing PV correctly Solution Superclasses are not the only possible abstractions Use composition: more flexible and can change at run time

What s wrong with inheritance? Car Aircraft Drone Vehicle goto() notifydriver() Uses delegation <<interface>> GoBehavior <<interface>> ControlBehavior DriveBehavior FlyingBehavior RemoteBehavior HumanBehavior

What s wrong with inheritance? Car Aircraft Drone Vehicle goto() notifydriver() <<interface>> GoBehavior <<interface>> ControlBehavior DriveBehavior FlyingBehavior RemoteBehavior HumanBehavior HeliCarDrone Not a problem now! userotors() usewheels()

GoF: Strategy Define a family of algorithms, encapsulate each one, and make them interchangeable Strategy lets the algorithm vary independently from clients that use it

Strategy Helps implementing OCP Obeys Protected Variations Favors composition (that is dynamic) over inheritance (that is static): has a over is a

Resources Books Eric Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra Head First Design Patterns O'Reilly Media, 2004 Online: http://www.vincehuston.org/dp/ http://www.oodesign.com/ http://www.informit.com/articles/article.aspx?p=1404 056