Introduction to Design Patterns

Similar documents
Introduction to Design Patterns

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Coordination Patterns

Patterns in Software Engineering

CS/CE 2336 Computer Science II

Lecture 13: Design Patterns

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

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

Design Patterns. Gunnar Gotshalks A4-1

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

Patterns for Decoupling

Design Patterns. An introduction

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

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

Why a Design Pattern. History of Design Pattern. Properties

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

Mining Relationships Between the Participants of Architectural Patterns

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

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

Lecture 19: Introduction to Design Patterns

Enforcing Singularity

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

Foundations of Software Engineering Design Patterns -- Introduction

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Programação de Sistemas Distribuidos

An Introduction to Patterns

A Metric of the Relative Abstraction Level of Software Patterns

WS01/02 - Design Pattern and Software Architecture

Towards a Java Framework for Knowledge Representation and Inference

An Introduction to Patterns

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

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

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

Chapter 12 (revised by JAS)

Design patterns generic models

Architectural Patterns

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

CS251 Software Engineering Lectures 18: Intro to DP

Design Patterns. Architectural Patterns. Contents of a Design Pattern. Dr. James A. Bednar. Dr. David Robertson

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

Design Patterns and Frameworks 1) Introduction

Initial contents proposal. List of topics. Common Architectural Styles. Architectural Styles. A sample from Elements of Software Architecture

A Metric for Measuring the Abstraction Level of Design Patterns

Object-Oriented Software Development Goal and Scope

Overview of Patterns: Introduction

Patterns of learning

An Introduction to Patterns and Pattern Languages. Overview. Patterns -- Why? Patterns -- Why?

Information Systems Analysis and Design. XIV. Design Patterns. Design Patterns 1

Broker Pattern. Teemu Koponen

Patterns Architectural Styles Archetypes

In this Lecture you will Learn: Design Patterns. Patterns vs. Frameworks. Patterns vs. Frameworks

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

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

INTERNAL ASSESSMENT TEST III Answer Schema

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

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

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

Programmazione. Prof. Marco Bertini

Tackling Design Patterns Chapter 3: Template Method design pattern and Public Inheritance. 3.1 Introduction... 2

Design Patterns! Acknowledgements!

Design Patterns. Produced by. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Towards Better Support for Pattern-Oriented Software Development

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

3 Product Management Anti-Patterns by Thomas Schranz

Work groups meeting 3

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

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

Reuse at Design Level: Design Patterns

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Outline. Design Patterns. Observer Pattern. Definitions & Classifications

A Reconnaissance on Design Patterns

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

Universal Communication Component on Symbian Series60 Platform

Design for Testability

Introduction and History

Patterns for Asynchronous Invocations in Distributed Object Frameworks

Slides copyright 1996, 2001, 2005, 2009, 2014 by Roger S. Pressman. For non-profit educational use only

OBJECT-ORIENTED MODELING AND DESIGN. Introduction

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

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

Singleton Pattern Creational

Work groups meeting 3

Patterns. Giovanni Sakti. in Software Engineering. Starqle

Crash course on design patterns

Object-Oriented Design

Cocoa Design Patterns. Erik M. Buck October 17, 2009

Using Design Patterns in Java Application Development

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 PATTERN MATCHING

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

Introduction of Pattern Oriented Software Concepts in Ground Stations

Design Patterns. Definition of a Design Pattern

SDC Design patterns GoF

Mod4j Application Architecture. Eric Jan Malotaux

Introduction to Patterns and Frameworks

Concurrency Control with Java and Relational Databases

Enterprise Integration Patterns Exemplified in Java Business Integration

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

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

Transcription:

Dr. Michael Eichberg Software Technology Group Department of Computer Science Technische Universität Darmstadt Introduction to Software Engineering Introduction to Design Patterns

Patterns 2 PATTERNS A pattern describes... a problem which occurs over and over again in our environment, 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. (Christopher Alexander)

On Patterns... Patterns are proven Proven software practice Piece of literature Design Patterns 3 Building block, with various abstraction levels: Idiom (Coplien, 1991) Design Pattern (Gamma et al., 1995) Architectural Pattern (Buschmann et al., 1996) Aggressive disregard for originality.

Idioms are not (OO-) Design Patterns

An idiom is a low-level pattern (typically specific to a programming language). Idioms 5 String copy in C (s and d are char arrays) while (*d++=*s++); Example

An idiom is a low-level pattern (typically specific to a programming language). Idioms 6 Lazy instantiation of Singletons in Java (Double-checked Locking Idiom) private static Device device = null; public static Device instance() { if (device == null) { synchronized (Device.class) { if (device == null) { device = new Device(); } } } return device; } Requires Java 6 or newer to work correctly! Example

Template Method A first Design Pattern

The Template Method Pattern Design Patterns 8 Design Goal We want to implement an algorithm such that certain (specific) parts can be adapted / changed later on.

The Template Method Pattern Design Patterns 9 Define a skeleton of an algorithm in an operation, but defer some steps to subclasses Often found in frameworks and APIs write(byte[] b) write(byte[] b, int off, int len) write(int) FileOutputStream write(int) OutputStream {abstract} «method» { for (byte i : b) { write(i); } }

The Template Method Pattern Design Patterns 10 Use the Template Method Pattern to. separate variant and invariant parts avoid code duplication in subclasses; the common behavior is factored and localized in a common class control subclass extensions templatemethod() opa() opb() ConcreteClass opa() opb() AbstractClass {abstract} «method» {... opa();... opb(); } The template method is the method that defines the algorithm using abstract (and concrete) operations. Besides, abstract operations (must be overridden) it is possible to define hook operations (may be overridden).

Design Patterns - Motivation Design Patterns 11 Designing reusable, extensible software is hard Novices are overwhelmed Experts draw from experience Some design solutions reoccur Understanding reoccurring solutions has several facets: Know when to apply Know how to establish it in a generic way Know the consequence (trade-offs)

Architectural Patterns are not Design Patterns

Architectural patterns help to specify the fundamental structure of a software system, or important parts of it. Architectural Patterns 13 Architectural patterns have an important impact on the appearance of concrete software architectures Define a system s global properties, such as how distributed components cooperate and exchange data boundaries for subsystems The selection of an architectural pattern is a fundamental design decision; it governs every development activity that follows

Architectural patterns help to specify the fundamental structure of a software system, or important parts of it. Architectural Patterns 14 Architectural Patterns Pipes and Filters Broker Pattern MVC Broker Often, it is not sufficient to choose just one architectural pattern; instead it is necessary to combine several architectural patterns. More on this topic: Enterprise Application Design

Example Model-View Controller (MVC) Architectural Patterns 15 The MVC pattern describes a fundamental structural organization for interactive software systems The model contains the core functionality and data The model is independent of output representations or input behavior. The user interface is comprised of: Views that display information to the user The view obtains the data from the model. Controllers that handle user input Each view has a controller. A controller receives input. The events are then translated to service requests for the model or the view. All interaction goes through a controller.

Example Model-View Controller (MVC) Change Propagation Architectural Patterns 16 A change propagation mechanism ensures consistency between the user interface and the model. (The change-propagation mechanism is usually implemented using the Observer pattern / the Publisher-Subscriber pattern.) Basic Idea: A view registers itself with the model. If the behavior of a controller depends on the state of the model, the controller registers itself with the change propagation mechanism. View Model 1: change propagation change

Example Model-View Controller (MVC) Applicability Architectural Patterns 17 Use the MVC pattern for building interactive applications with a flexible human-computer interface. When... the same information should be presented differently (in different windows...) the display and behavior of the application must reflect data manipulations immediately porting the UI (or changing the L&F) should not affect code in the core of the application Data View 1 View 2

Example Model-View Controller (MVC) Structure Architectural Patterns 18 Controller View Model While the Controller and the View are directly coupled with the Model, the Model is not directly coupled with the Controller or the View.

Example Model-View Controller (MVC) Liabilities Architectural Patterns 19 (Liabilities =dt. Verantwortlichkeiten / Verbindlichkeiten) Increased complexity Using separate view and controller components can increase complexity without gaining much flexibility Potential for excessive number of updates Not all views are always interested in all changes. Intimate connection between view and controller

Architectural Patterns Recommended Resources Architectural Patterns 20 Pattern-Oriented Software Architecture - A System of Patterns; Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, Michael Stal; Wiley 1996 Design Patterns; Gamma et al. Patterns of Enterprise Application Architecture; Martin Fowler; Addison Wesley 2003

Properties of (Design) Patterns

Design Patterns - Benefits Design Patterns 22 Systematic (software-)development: Documenting expert knowledge Use of generic solutions Raising the abstraction level

Design Patterns - Essentials Design Patterns 23 to tailor =dt. anpassen a pattern has a name the problem has to reoccur to make the solution relevant in situations outside the immediate one it has to be possible to tailor the solution to a variant of the problem A Design Pattern describes a solution for a problem in a context.

Essential Parts of Patterns Design Patterns 24 1. Pattern Name A short mnemonic to increase your design vocabulary. 2. Problem Description when to apply the pattern (conditions that have to be met before it makes sense to apply the pattern). 3. Solution The elements that make up the design, their relationships, responsibilities and collaborations. 4. Consequences Costs and benefits of applying the pattern. Language and implementation issues as well as impact on system flexibility, extensibility, or portability. The goal is to help understand and evaluate a pattern.

Template for Design Patterns (For Design Patterns as described by Gamma et al., 1995) Design Patterns 25 1. Name Intent 2. 3. Motivation Applicability Structure Participants Collaboration Implementation 4. Consequences 5. Known Uses Related Patterns

To document a used design pattern use the participant names of the pattern to specify a class role in the implementation of patterns. Design Patterns 26 Template Method Pattern Use of the Template Method Pattern in Java AbstractClass {abstract} templatemethod() opa() opb() ConcreteClass «method» {... opa();... opb(); } Template Method abstract class concrete class OutputStream {abstract} write(byte[] b) write(byte[] b, int off, int len) write(int) FileOutputStream opa() opb() write(int)

Levels of Consciousness for a Design Pattern Design Patterns 27 1.Innocence 2.Known tricks 3.Competent trick application 4.Applicability & consequences known 5.Wide knowledge of patterns & their interaction 6.Capable of capturing knowledge into literate form

Design Patterns Serve Multiple Purposes Design Patterns 28 Elements of Reusable Software Reuse of Design patterns foster reusability rather than code Communication design vocabulary Documentation information chunks Teaching passing on culture Language Design high level languages

Design Patterns 29 Patterns enable the construction of high-quality software architectures.

Design Patterns 30 A software design pattern describes... a commonly recurring structure of interacting software components that solve a general software design problem within a particular context.

Design Patterns - Occurrences Design Patterns 31 chess literature agriculture architecture from rules to expertise oldest reference wisdom vs. science pioneering work software design Light from two sides Place at Window Deep terrace Patterns in Architecture

Design Patterns =dt. Entwurfsmuster Design Patterns 32 Main Focus (Content relevant for the exam!) Alternative Book

Summary

Goal of the Lecture 34 The goal of this lecture is to enable you to systematically carry out small(er) software projects that produce quality software. Idioms, Design Patterns and Architectural Patterns help you to solve recurring problems (at different abstraction levels) and to immediately understand the benefits and tradeoffs. Patterns enable you to talk about the design of your application at a higher abstraction level.