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

Similar documents
SDC Design patterns GoF

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

Object-Oriented Design

Using Design Patterns in Java Application Development

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

Design Patterns. An introduction

Introduction and History

Object-Oriented Oriented Programming

Design patterns. Jef De Smedt Beta VZW

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

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

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

Applying the Observer Design Pattern

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

Brief Note on Design Pattern

What is Design Patterns?

Applying the Decorator Design Pattern

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

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

Object Oriented Paradigm

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

CS/CE 2336 Computer Science II

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

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

Design Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern.

Coordination Patterns

2.1 Design Patterns and Architecture (continued)

Applying the Factory Method Design Pattern

6.3 Patterns. Definition: Design Patterns

Topics in Object-Oriented Design Patterns

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

Design patterns. OOD Lecture 6

2.1 Design Patterns and Architecture (continued)

DESIGN PATTERN - INTERVIEW QUESTIONS

What is Design Patterns?

Lecture 20: Design Patterns II

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

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

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

Introduction to Software Engineering: Object Design I Reuse & Patterns

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

Egon Borger (Pisa) Capturing Design Pattern Abstractions by ASMs

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

DESIGN PATTERNS SURESH BABU M ASST PROFESSOR VJIT

Object-oriented Software Design Patterns

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

The GoF Design Patterns Reference

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

1 Software Architecture

Application Architectures, Design Patterns

What is Design Patterns?

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

Design Patterns Reid Holmes

A Metric for Measuring the Abstraction Level of Design Patterns

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

An Introduction to Patterns

Object-Oriented Design

Second Midterm Review

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Information systems modelling UML and service description languages

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

3 Product Management Anti-Patterns by Thomas Schranz

Lecture 19: Introduction to Design Patterns

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

A Metric of the Relative Abstraction Level of Software Patterns

Design Patterns. Softwaretechnik. Matthias Keil. Albert-Ludwigs-Universität Freiburg

Foundations of Software Engineering Design Patterns -- Introduction

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

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

Design pa*erns. Based on slides by Glenn D. Blank

Design Patterns. Gunnar Gotshalks A4-1

Tuesday, October 4. Announcements

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

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

Design patterns generic models

Design Patterns. Software Engineering. Sergio Feo-Arenis slides by: Matthias Keil

Last Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005


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

CS251 Software Engineering Lectures 18: Intro to DP

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

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

UNIT I Introduction to Design Patterns

CS 2720 Practical Software Development University of Lethbridge. Design Patterns

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

Softwaretechnik. Design Patterns. Matthias Keil. Albert-Ludwigs-Universität Freiburg

Why a Design Pattern. History of Design Pattern. Properties

Design Patterns: Structural and Behavioural

Softwaretechnik. Design Patterns. Stephan Arlt SS University of Freiburg. Stephan Arlt (University of Freiburg) Softwaretechnik SS / 47

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

Composite Pattern. IV.4 Structural Pattern

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

THOMAS LATOZA SWE 621 FALL 2018 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. CSE870: Advanced Software Engineering (Design Patterns): Cheng

UNIT I Introduction to Design Patterns

WS01/02 - Design Pattern and Software Architecture

Design Patterns. (and anti-patterns)

Transcription:

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

Introduction Slide 2 Basic Idea The same (well-established) schema can be reused as a solution to similar problems. Muster Abstraktion Anwendung Problemlösung 1 Problemlösung 2 Problemlösung 3 Advantages Reusing tried and tested solution principles (quality, cost savings) abstract documentation of designs common vocabulary for communication among developers

Morale Slide 3 Do not reinvent the wheel!

History Slide 4 1977 Alexander: Architecture patterns for buildings and urban development 1980 Smalltalk s MVC principle (Model View Controller) Since 1990 Object-oriented patterns in software engineering 1995 Design Pattern catalogue of Gamma, Helm, Johnson, Vlissides (GoF Gang of Four ) Buschmann, Frank, Regine Meunier, Hans Rohnert, Peter Sommerlad (1996). Pattern-Oriented Software Architecture, Volume 1: A System of Patterns. John Wiley & Sons. ISBN 0-471-95869-7 Martin Fowler (2002). Patterns of Enterprise Application Architecture. Addison-Wesley. ISBN 978-0321127426. Gregor Hohpe, Bobby Woolf (2003). Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions. Addison-Wesley. ISBN 0-321-20068-3. Eric Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra (2004). Head First Design Patterns. O Reilly Media. ISBN 0-596-00712-4.

Essential Elements of a Software Design Pattern Slide 5 Name of the pattern Description of the class of problems the pattern is applicable to Description of an example of use Description of the solution (structure, responsibilities,...) Description of the consequences (cost-benefit analysis)

Design Pattern Catalogue (GoF) Slide 6 Description Schema for a Design Pattern Pattern Name and Classification The pattern s name conveys the essence of the pattern succinctly. A good name is vital, because it will become part of your design vocabulary. Intent A short statement that answers the following question: What does the design pattern do? What is its rational and intent? What particular design issue or problem does it address? Also Known As Other well-known names for the pattern, if any. Motivation A scenario that illustrates a design problem and how the class and oject structures in the pattern solve the problem. The scenario will help you understand the more abstract descriptions of the pattern that follows.

Applicability What are the situations in which the design pattern can be applied? What are examples of poor designs that the pattern can address? How can you recognize these situations? Structure A graphical representation of the classes in the pattern using a notation based on the Object Modelling Technique (OMT). We also use interaction diagrams to illustrate sequences of requests and collaborations between objects. Participants The classes and/or objects participating in the design pattern and their responsibilities. Collaborations How the participants collaborate to carry out their responsibilities. Consequences How does the pattern support its objectives? What are the trade-offs and results of using the pattern? What aspects of system structure does it let you vary independently? Slide 7

Implementation What pitfalls, hints, or techniques should you be aware of when implementing the pattern? Are there language-specific issues? Sample Code Code fragments that illustrate how you might implement the pattern in C++ or Smalltalk. Known Uses Examples of the pattern found in real systems. We include at least two examples from different domains. Related Patterns What design patterns are closely related to this one? What are the important differences? With which other patterns should this one be used? Slide 8

Classification of Design Patterns Slide 9 Creational Patterns (concern the creation of objects) Abstract Factory Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Builder Separate the construction of a complex object from its representation so that the same construction process can create different representations. Factory Method Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Prototype Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Singleton Ensure a class only has one instance, and provide a global point of access to it. Structural Patterns (concern the structural composition of classes or objects) Adapter Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn t otherwise because of incompatible interfaces. Bridge Decouple an abstraction from its implementation so that the two can vary independently. Composite Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

Structural Patterns (continued) Decorator Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Facade Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. Flyweight Use sharing to support large numbers of fine-grained objects efficiently. Proxy Provide a surrogate or placeholder for another object to control access to it. Behavorial Patterns (concern the interaction of objects and the distribution of responsibilities) Chain of Responsibility Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. Command Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. Interpreter Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. Iterator Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Slide 10

Mediator Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. Memento Without violating encapsulation, capture and externalize an object s internal state so that the object can be restored to this state later. Observer Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. State Allow an object to alter its behaviour when its internal state changes. The object will appear to change its class. Strategy Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it. 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. Visitor Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the element on which it operates. Slide 11

Overview Slide 12 1. Singleton (creational) 2. Abstract Factory (creational) 3. Composite (structural) 4. Proxy (structural) 5. Iterator (behavioural) 6. Observer (behavioural pattern) 7. State (behavioural pattern)

Example 1: Singleton (Creational Pattern) Slide 13 Intent Ensures that a class has only one instance; provides a global access point to it. Structure Known uses: java.lang.runtime; org.eclipse.core.runtime.plugin. Example:...

Example 2: Abstract Factory (Creational Pattern) Slide 14 Intent Provides an interface for creating families of related or dependent objects without specifying their concrete classes. Structure AbstractFactory Client createproducta() createproductb() AbstractProductA ConcreteFactory1 ConcreteFactory2 ProductA2 ProductA1 createproducta() createproductb() createproducta() createproductb() AbstractProductB ProductB2 ProductB1 Known uses: Toolkit in AWT.

Example 3: Composite (Structural Pattern) Slide 15 Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Structure Client 1 Component operation() add(c: Component) remove(c: Component) getchild(n: Integer) * children Leaf Composite operation() operation() add(c: Component) remove(c: Component) getchild(n: Integer) for all g in children do g.operation(); Known uses: Composite and Control in SWT; geometric figures (tutorial).

Example 4: Proxy (Structural Pattern) Slide 16 Intent Provide a surrogate or placeholder for another object to control access to it. Structure Known uses: Plug-in mechanisms.

Example 5: Iterator (Behavioural Pattern) Slide 17 Intent Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Structure Known uses: Java API.

Example 6: Observer (Behavioural Pattern) Slide 18 Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Structure update() Observer * observers Subject attach(o: Observer) detach(o: Observer) notify() for all o in observers do o.update(); ConcreteObserver observerstate update() observerstate = subject.getstate(); 1 subject ConcreteSubject subjectstate setstate() getstate() return subjectstate; Known uses: Event listeners in user interfaces (SWT).

Interactions Slide 19 :AConcreteObserver :AnotherConcreteObserver :AConcreteSubject setstate() notify() update() getstate() update() getstate()

Example 7: State (Behavioural Pattern) Slide 20 Intent Allow an object to alter its behaviour when its internal state changes. The object will appear to change its class. Structure state.handle(); Context request() 1 state handle() State ConcreteStateA handle() ConcreteStateB handle()... Example of use: Realization of state diagrams by state objects.

MVC Architecture Slide 21 2: handleevent() 7: showdata() :Controller 3: manipulate() :View 4: service() 1: attach() 6: getdata() 5: update() :Model