CPSC 310 Software Engineering. Lecture 11. Design Patterns

Similar documents
Design Patterns. An introduction

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

Lecture 13: Design Patterns

An Introduction to Patterns

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

CS/CE 2336 Computer Science II

Object-Oriented Design

Tuesday, October 4. Announcements

An Introduction to Patterns

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

Design Patterns. Gunnar Gotshalks A4-1

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

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

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

Patterns of learning

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

What is Design Patterns?

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

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

Programmazione. Prof. Marco Bertini

CS251 Software Engineering Lectures 18: Intro to DP

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

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

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

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

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Crash course on design patterns

Chapter 12 (revised by JAS)

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

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

Using Design Patterns in Java Application Development

Work groups meeting 3

What is Design Patterns?

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

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

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

DESIGN PATTERN - INTERVIEW QUESTIONS

The GoF Design Patterns Reference

CS560. Lecture: Design Patterns II Includes slides by E. Gamma et al., 1995

Topics in Object-Oriented Design Patterns

Introduction and History

Outline. Design Patterns. Observer Pattern. Definitions & Classifications

3 Product Management Anti-Patterns by Thomas Schranz

Object-Oriented Design

1 Software Architecture

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

What is Design Patterns?

Summary of the course lectures

Patterns. Giovanni Sakti. in Software Engineering. Starqle

CHAPTER 6: CREATIONAL DESIGN PATTERNS

A Rapid Overview of UML

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

Application Architectures, Design Patterns

Work groups meeting 3

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

Applying the Observer Design Pattern

CSC207H: Software Design Lecture 6

EINDHOVEN UNIVERSITY OF TECHNOLOGY

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

Design Patterns גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Foundations of Software Engineering Design Patterns -- Introduction

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

Lecture Material. Design Patterns. Visitor Client-Server Factory Singleton

Design Patterns. CSC207 Fall 2017

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

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

MSO Object Creation Singleton & Object Pool

Design Patterns. Definition of a Design Pattern

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

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

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

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

SOFTWARE PATTERNS. Joseph Bonello

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

Design Patterns. James Brucker

Object Oriented Paradigm

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

SDC Design patterns GoF

Lecture 19: Introduction to Design Patterns

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

Introduction to Design Patterns

CPS122 Lecture: Design Patterns Last revised March 20, 2012

Object-oriented Software Design Patterns

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

Introduction to Testing and Maintainable code

Design Patterns. Lecture 10: OOP, autumn 2003

What are patterns? Design Patterns. Design patterns. Creational patterns. The factory pattern. Factory pattern structure. Lecture 10: OOP, autumn 2003

Introduction to Design Patterns

Refactoring. Why? When? What?

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

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Improve Your SystemVerilog OOP Skills

Coordination Patterns

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

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


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

GOF Patterns Applied

Transcription:

CPSC 310 Software Engineering Lecture 11 Design Patterns

Learning Goals Understand what are design patterns, their benefits and their drawbacks For at least the following design patterns: Singleton, Observer, Adapter, you will be able to describe them, know when to use them or not and give examples of situations where you could use them. 2/26

A bit of history Christopher Alexander 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 A pattern expresses a relation between a certain context, a problem and a solution 3/26

A bit of history, continued OOP World The Gang of Four - GoF Gamma, E., Helm, R., Johnson, R., & Vlissides, J. (1994). Design patterns: elements of reusable object-oriented software 4/26 image designed by Jessica Lock from the Noun Project

To be, or not to be A Design Pattern IS: a way to benefit from the collective experience of skilled software developers an easy way to communicate about common problems A Design Pattern IS NOT: the complete solution to your problem the only solution to your problem (but it's a proven one) something you should use if you do not understand it 5/26

Pattern Classification Creational Patterns How an object can be created Structural Patterns How objects can be composed Behavioral Patterns How objects communicate 6/26

Singleton pattern Intent: Make sure a class has only one instance, and provide a global point of access to it Participants & Structure: Singleton - instance : Singleton - Singleton() + getinstance() : Singleton 7/26

Singleton pattern public class Singleton { private static Singleton instance = null; private Singleton() { } public static synchronized Singleton getinstance() { if (instance == null) { instance = new Singleton(); } return instance; } } 8/26

Singleton pattern public class Singleton { private static Singleton instance = null; private Singleton() { } public static synchronized Singleton getinstance() { if (instance == null) { instance = new Singleton(); } return instance; } } 9/26

Singleton pattern To which category belongs this pattern? Creational Patterns How an object can be created Structural Patterns How objects can be composed Behavioral Patterns How objects communicate 10/26

Observer pattern Intent: Ensure that, when an object changes his state, all its dependents are notified and updated automatically Participants & Structure: 11/26

Observer pattern [example] Auctioneer (Subject) 4 8 15 16 Bidders (Observers) 12/26

Observer pattern [example] Auctioneer (Subject) register bidders 4 8 15 16 Bidders (Observers) 13/26

Observer pattern [example] Auctioneer (Subject) 1. accept new bid 4 2. notify new bid 8 15 16 Bidders (Observers) 14/26

Observer pattern [example] Auctioneer (Subject) retrieve new price 4 8 15 16 Bidders (Observers) 15/26

Observer pattern To which category belongs this pattern? Creational Patterns How an object can be created Structural Patterns How objects can be composed Behavioral Patterns How objects communicate 16/26

Adapter pattern Intent: Convert the interface of a class into another interface that clients expect. Participants & Structure: 17/26

Adapter pattern Power supply adapter analogy 18/26

Adapter pattern Concrete example 19/26

Adapter pattern To which category belongs this pattern? Creational Patterns How an object can be created Structural Patterns How objects can be composed Behavioral Patterns How objects communicate 20/26

Design Pattern Collection Factory Singleton Decorator Proxy Template Composite Adapter Observer http://sourcemaking.com/design_patterns 21/26

Anti Pattern A bad solution to a recurring problem "Strong" code smell A good pattern in the wrong context can lead to an anti-pattern 22/26

Anti Pattern Several categories Development Architecture Management http://c2.com/cgi/wiki?antipatternscatalog http://sourcemaking.com/antipatterns 23/26

Eg: Golden Hammer Problem: You need to choose technologies for your development, and you are of the belief that you must choose exactly one technology to dominate the architecture. Context: You need to develop some new system or piece of software that doesn't fit very well the technology that the development team are familiar with. Forces: The development team are committed to the technology they know The development team are not familiar with other technologies Other, unfamiliar, technologies are seen as risky It is easy to plan and estimate for development in the familiar technology Supposed Solution: Use the familiar technology anyway. The technology (or concept) is applied obsessively to many problems, including where it is clearly inappropriate. Refactored Solution: Expanding the knowledge of developers through education, training, and book study groups exposes developers to new solutions. http://sourcemaking.com/antipatterns/golden-hammer 24/26

Eg. Singleton Overuse Problems violate information hiding since dependencies are hidden in the code and not expressed in the interface can cause high coupling You must have a good damn reason to use it The fact that you know it is not enough public void somemethod()... Profile.getInstance().getUserLevel() public void somemethod(profile profile)... 25/26 profile.getuserlevel()

Design Pattern Drawbacks Can make the design more complex if not needed Start simple and then refactor by using a design pattern if it is justified Do not try to anticipate future needs too much Can lead to bad design if not applied in the right context 26/26