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

Similar documents
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

SDC Design patterns GoF

What is Design Patterns?

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

Object-Oriented Design

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

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

Design Patterns. An introduction

What is Design Patterns?

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

Using Design Patterns in Java Application Development

What is Design Patterns?

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

DESIGN PATTERN - INTERVIEW QUESTIONS

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

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

Brief Note on Design Pattern

A Reconnaissance on Design Patterns

Design patterns generic models

Information systems modelling UML and service description languages

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

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

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

Object-Oriented Design

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

The GoF Design Patterns Reference

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

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

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

An Introduction to Patterns

Introduction to Software Engineering: Object Design I Reuse & Patterns

Object Oriented Paradigm

1 Software Architecture

Object-oriented Software Design Patterns

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

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

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

Application Architectures, Design Patterns

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

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

Applying Design Patterns to SCA Implementations

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

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

Reuse at Design Level: Design Patterns

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

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

2.1 Design Patterns and Architecture (continued)

Tuesday, October 4. Announcements

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

2.1 Design Patterns and Architecture (continued)

CS 247: Software Engineering Principles. Design Patterns

Design patterns. OOD Lecture 6

Applying the Observer Design Pattern

Creational Design Patterns

Design Patterns Reid Holmes

Topics in Object-Oriented Design Patterns

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

Lecture 20: Design Patterns II

Design Pattern- Creational pattern 2015

Applying the Decorator Design Pattern

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

Design Patterns: Structural and Behavioural

Appendix-A. A.1 Catalogues of Design Patterns. Below is the definition for each design pattern using the FINDER notation, followed

Review Software Engineering October, 7, Adrian Iftene

SYLLABUS CHAPTER - 1 [SOFTWARE REUSE SUCCESS FACTORS] Reuse Driven Software Engineering is a Business

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

INSTITUTE OF AERONAUTICAL ENGINEERING

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

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

Object-Oriented Oriented Programming

Second Midterm Review

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

UNIT I Introduction to Design Patterns

Design patterns. Jef De Smedt Beta VZW

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

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

CS/CE 2336 Computer Science II

CS251 Software Engineering Lectures 18: Intro to DP

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

Applying the Factory Method Design Pattern

Design Pattern and Software Architecture: IV. Design Pattern

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

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

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

GoF Design Pattern Categories

Introduction and History

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

3 Product Management Anti-Patterns by Thomas Schranz

Design Patterns. Gunnar Gotshalks A4-1

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

UNIT I Introduction to Design Patterns

Summary of the course lectures

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

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

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

Design for change. You should avoid

Software Eningeering. Lecture 9 Design Patterns 2

The Design Patterns Matrix From Analysis to Implementation

Design Patterns Lecture 2

Transcription:

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

Definition A pattern is a reusable solution to a commonly occurring problem within a given context. A pattern is a proposed way to resolve a problem. In the field of software design, examples of a problem may be: Control the creation of objects. Assign responsibilities to classes or objects. Manage collections of classes and objects. Adapt the runtime behavior of objects. Context may differentiate two structurally similar patterns. A pattern may be used for both design and refactoring, in order to improve quality. Main reference for design patterns: Design Patterns: Elements of Reusable Object Oriented Software by E. Gamma, R. Helm, R. Johnson, and J. Vlissides (Gang of four). It contains 23 patterns, classified into 3 categories: creational, behavioral and structural. 06/2011, Manuel Mastrofini 2

Classification of patterns (GoF) A pattern has: Name Purpose: what a pattern does. Creational: facilitate object creation. Structural: support composition of classes and objects. Behavioral: help distribute responsibilities and control interactions. Scope: if a pattern applies to classes or to objects. Class patterns include compile-time defined relationships (generalization). Object patterns allow relationships to be created and changed at run-time. Creational Structural Behavioral Abstract Factory (o) Adapter (c/o) Chain of responsibility (o) Observer (o) Builder (o) Bridge (o) Command (o) State (o) Factory Method (c) Composite (o) Interpreter (o) Strategy (o) Prototype (o) Decorator (o) Iterator (o) Template method (c) Singleton (o) Facade (o) Mediator (o) Visitor (o) Flyweight (o) Proxy (o) Memento (o) 06/2011, Manuel Mastrofini 3

Why (and what) patterns Patterns help create high quality software, i.e. encapsulation, modularity, flexibility, ease of use, evolution, extensibility. Algorithmic independency: c: Builder; s:; b: Iterator, Strategy, Template Method, Visitor. Creating an object without specifying a class explicitly: c: Abstract Factory, Factory Method, Prototype. Independence from specific operations: b: Chain of responsibility, Command. Independence from object representation or implementation: c: Abstract Factory; s:bridge, Proxy. Loose coupling: c: Abstract Factory; s: Bridge, Façade; b: Command, Mediator, Observer. Extending functionality by sub-classing: s: Bridge, Composite, Decorator; b:command, Observer, Strategy. Ability to alter classes conveniently: c:adapter; b:decorator, Visitor. 06/2011, Manuel Mastrofini 4

Pattern inter-relationships There are many relationships among patterns. Some patterns are alternative. One has to be selected. Some patterns are complementary. They are expected to be combined. Parts of a complex pattern may be implemented by using other patterns. 06/2011, Manuel Mastrofini 5

Creational patterns

Singleton Intent: ensure a class only has one instance at most, and provide a global point of access to it. Singleton: defines an Instance operation that lets clients access its unique instance. Instance is a class operation. Variant: Instead of one instance, the number of class instances may be controlled to be any number. 06/2011, Manuel Mastrofini 7

Factory Method (Virtual Constructor) Intent: define an interface for creating an object, but let subclasses decide which class to instantiate. Product: defines the interface of objects the factory method creates. ConcreteProduct: implements the Product interface. Creator: declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object. The Creator may call the factory method to create a Product object. ConcreteCreator: overrides the factory method to return an instance of a ConcreteProduct. 06/2011, Manuel Mastrofini 8

Prototype Intent: Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Prototype: declares an interface for cloning itself. ConcretePrototype: implements an operation for cloning itself. Client: creates a new object by asking a prototype to clone itself. Variant: Create a Prototype Manager class which manages a registry containing all prototypes, so that the Client ask for a prototype by providing a key. 06/2011, Manuel Mastrofini 9

Abstract Factory (Kit) Intent: provide an interface for creating families of related or dependent objects without specifying their concrete classes. AbstractFactory: interface for operations that create abstract product objects. It could be a singleton and generally leverages the factory method pattern. ConcreteFactory: implements the operations to create concrete product objects. AbstractProduct: interface for a type of product object. ConcreteProduct: to be created by the corresponding concrete factory. Variant: If there are many product families, then the Prototype pattern could be used; in this case, there is no need to create a ConcreteFactory for each family. 06/2011, Manuel Mastrofini 10

Builder Intent: Separate the construction logic of a complex object from its representation so that the same construction process can create different representations. Builder: specifies an abstract interface for creating parts of a Product object. Director: constructs an object using the Builder interface. Product: represents the complex object under construction. ConcreteBuilder: constructs and assembles parts of the product by implementing the Builder interface and defines the process by which it is assembled; comprises classes that define the constituent parts; defines and keeps track of the representation it creates; provides an interface for retrieving the product. 06/2011, Manuel Mastrofini 11

Structural patterns Part 1

Adapter (Wrapper) Intent: It converts the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Target: defines the domain-specific interface that Client uses. Adapter: adapts the interface of Adaptee to the Target interface. In inherits from Adaptee (class adapter) or have a composition with it (object adapter). In the first case, subclasses of Adaptee cannot leverage the pattern adaption Adaptee: defines an existing interface that needs adapting. Variant: When two views of the same entity are used by two clients, a two-way adapter can be built by using multiple inheritance: the adapter inherits from the two classes used by the two clients. 06/2011, Manuel Mastrofini 13

Bridge (Body, Handle) Intent: It decouples an abstraction from its implementation so that the two can vary independently and be extended independently. Abstraction: defines the abstraction's interface and maintains a reference to an object of type Implementor. It could be aware of the Implementor s hierarchy and use the right subclass, or it could leverage the Abstract Factory pattern to instantiate the right subclass without statically coupling any concrete implementor to the Abstraction. RefinedAbstraction: extends the interface defined by Abstraction. Implementor: defines the interface for implementation classes. Typically the Implementor interface provides only primitive operations, and Abstraction defines higher-level operations based on these primitives. ConcreteImplementor: defines the concrete implementation of Implementor. 06/2011, Manuel Mastrofini 14

Façade Intent: Provide a unified interface to a set of interfaces in a subsystem. Façade: knows which subsystem classes are responsible for a request and delegates client requests to appropriate subsystem objects. It is generally a Singleton. Variant: If façade is abstract, then different implementation of the same subsystems can be configured by the client. This could be an implementation of Abstract Factory. 06/2011, Manuel Mastrofini 15