Design Patterns 1 Design Patterns: Elements of Reusable Object – Oriented Software Course of Software Engineering II Serena Fabbri.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Plab – Tirgul 12 Design Patterns
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Design Patterns. CS351 - Software Engineering (AY2007)Slide 2 Behavioral patterns Suppose we have an aggregate data structure and we wish to access the.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Design Patterns William A. Hoffman NYU OOP Class.
(c) 2010 University of California, Irvine – André van der Hoek1June 29, 2015 – 08:55:05 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Basic Design Patterns 1. Introduction Gabriel Mañana Ed. 453 Of. 120 Ext
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Design Patterns Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Powerpoint Templates Page 1 Powerpoint Templates What is Design Patterns ? by Indriati Teknik Informatika – UB.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns Introduction
Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since 1987 Program Director, Los Angeles Visual Foxpro Developers.
Design Patterns: Elements of Reusable Object – Oriented Software Web Apps and Services.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
object oriented Principles of software design
Software Engineering Lecture 7 - Design Patterns
Decorator Pattern Intent
Informatics 122 Software Design II
Informatics 122 Software Design II
Presentation transcript:

Design Patterns 1 Design Patterns: Elements of Reusable Object – Oriented Software Course of Software Engineering II Serena Fabbri

Design Patterns 2 Design Pattern Introduction: why a design pattern? History of design pattern What is a design pattern How we describe design pattern Classification of desing pattern Examples of design pattern Conclusions Bibliography

Design Patterns 3 Why a Design Pattern Reusability:one of Wasserman’s rules(1996)for an efficient and actual SE discipline Helping new designers to have a more flexible and reusable design Improving the documentation and maintenance of existing system by furnishing an explicit specification of class and object interactions and their intent

Design Patterns 4 History of Design Pattern 1979:Christopher Alexander,architect, “The Timeless Way of Building”,Oxford Press 1987:OOPSLA (Object Oriented Programming System),Orlando, presentation of design pattern to the community OO by Ward Cunningham and Kent Beck 1995:Group of Four alias E.Gamma, R.Helm,R.Johnson and J.Vlissides : “Design Pattern:Elements of Reusable OO software”

Design Patterns 5 What Is a Design Pattern  A design pattern is a descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context  A pattern is made by four elements:  name name  problem problem  solution solution  consequences consequences

Design Patterns 6 Name of Design Pattern  Describe a design problems and its solutions in a word or two  Used to talk about design pattern with our colleagues  Used in the documentation  Increase our design vocabulary  Have to be coherent and evocative

Design Patterns 7 Problem Describes when to apply the patterns Explains the problem and its context Sometimes include a list of conditions that must be met before it makes sense to apply the pattern Have to occurs over and over again in our environment

Design Patterns 8 Solution Describes the elements that make up the design, their relationships, responsibilities and collaborations Does not describe a concrete design or implementation Has to be well proven in some projects

Design Patterns 9 Consequences Results and trade-offs of applying the pattern Helpful for describe design decisions, for evaluating design alternatives Benefits of applying a pattern Impacts on a system’s flexibility,extensibility or portability

Design Patterns 10 Description of Design Pattern Pattern name and classification Pattern name and classification contains the essence of pattern succinctly Become part of your design vocabulary Intent Intent What does the pattern do ? What particular problem does it address ?

Design Patterns 11 Description of Design Pattern Motivation Illustrate a design problem and how the class and the object structures solve the problem Applicability Applicability In which situations the pattern can be applied? How can you recognize these situations ?

Design Patterns 12 Description of Design Pattern Structure Structure Graphical representation of the classes and their collaborations in the pattern Participants Participants Class Objects Responsibilities

Design Patterns 13 Description of Design Pattern Collaborations Collaborations How the participants collaborate to carry out their responsibilities Consequences Consequences How does the pattern support its objectives? What are the trade-offs and results of using the pattern?

Design Patterns 14 Description of Design Pattern Implementation Implementation Sample Code Sample Code Known Uses Known Uses Examples of the pattern found in real systems

Design Patterns 15 Description of Design Pattern Related Patterns Related Patterns What design patterns are closely related to this one? What are the important differences ?

Design Patterns 16 By purpose and by scope Creational patterns Creational patterns Creational patterns Creational patterns Abstract the instantiation process Make a system independent to its realization Class Creational use inheritance to vary the instantiated classes Object Creational delegate instantiation to an another object Classification of Design Pattern

Design Patterns 17 Classification of Design Pattern Structural patterns Structural patterns Structural patterns Class Structural patterns concern the aggregation of classes to form largest structures Object Structural pattern concern the aggregation of objects to form largest structures

Design Patterns 18 Classification of Design Pattern Behavioral patterns Behavioral patterns Behavioral patterns Concern with algorithms and assignment of responsibilities between objects Describe the patterns of communication between classes or objects Behavioral class pattern use inheritance to distribute behavior between classes Behavioral object pattern use object composition to distribute behavior between classes

Design Patterns 19 Classification of design patterns ( a view) CreationalStructuralBehavioral Factory MethodAdapterInterpreter Template Method Abstract FactoryAdapterChain of Responsibility BuilderBridgeCommand PrototypeCompositeIterator SingletonDecoratorMediator FaçadeMemento FlyweightObserver ProxyState Strategy VisitorClassObject purpose Scope

Design Patterns 20 Creational Pattern Singleton Ensure a class only has one instance Provide a global point of access to it Abstract Factory: Provide an interface for creating families of related or dependent objects without specifying their concrete classes

Design Patterns 21 Creational Pattern Factory Method: Define an interface for creating an object but let subclasses decide which class to instantiate Lets a class defer instantiation to subclasses Prototype Specify the kinds of objects to create using a prototypical instance Create new objects by copying this prototype

Design Patterns 22 Creational Pattern Builder: Separate the construction of a complex object from its representation so that the same construction process can create different representations

Design Patterns 23 Structural Pattern Composite Compose objects into tree structures to represent part-whole hierarchies Lets clients treat individual objects and compositions of objects uniformly Decorator Attach additional responsibilities to an object dynamically Provide a flexible alternative to subclassing for extending functionality

Design Patterns 24 Structural Pattern Adapter: Convert the interface of a class into another interface clients expect 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

Design Patterns 25 Structural Pattern Façade Provide a unified interface to a set of interfaces in a subsystem Defines an higher-level interface that makes the system easier to use Flyweight Use sharing to support large numbers of fine- grained objects efficiently

Design Patterns 26 Structural Pattern Proxy Provide a surrogate or placeholder for another object to control access to it

Design Patterns 27 Behavioral Pattern Iterator Provide a way to access the elements of an aggregate object without exposing its representation Command Encapsulate a request as an object, thereby letting you parameterize clients with different requests

Design Patterns 28 Behavioral Pattern Interpreter Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language Mediator Define an object that encapsulate how a set of objects interact Promotes loose coupling by keeping objects from referring to each other explicitly Lets you vary their interaction independently

Design Patterns 29 Behavioral Pattern Memento Capture and externalize an object’s internal state Observer Define a one-to-many dependency between objects so when one of them change state all its dependents are updated automatically

Design Patterns 30 Behavioral Pattern State Allow an object to alter its behavior when its internal state changes The object will appear to change its class Visitor Represent an operation to be performed on the elements of an object structure Lets you define a new operation without changing the classes of the elements on which operates

Design Patterns 31 Behavioral Pattern Strategy Define a family of algorithms Encapsulate each one Make them interchangeable Lets the algorithms vary independently from clients that use it Chain of responsibilities Avoid coupling the sender of a request to its receiver by giving more then one object a chance to handle the request Chain the receiving objects and pass the request along the chain until an object handles it

Design Patterns 32 Singleton Pattern Motivation we need to have exactly only one instance for a class (ex. Printer spooler) Make the class itself responsible for keeping track of its sole instance The class provide a way to access the instance Applicability There must be only one instance of a class accessible from a well-known point

Design Patterns 33 Singleton Pattern Structure Singleton Static Instance() SingletonOperation() GetSingletonData() Static uniqueInstance SingletonData Return uniqueInstance

Design Patterns 34 Singleton Pattern Participants Singleton class Collaborations Access only through Singleton’s instance operation Consequences Controlled access to sole instance Permits refinement of operation and representation More flexible than class operations

Design Patterns 35 Example of Singleton use “Lotteria Algebrica” We had to have only one instance for class Director. We simply solve our problem using Singleton Pattern Director Static Instance() Given(n_ticket:int):void Error():void Static UniqueInstance

Design Patterns 36 Decorator Pattern Motivation Add responsibilities to individual object not to an entire class conforming the interface of the component decorated

Design Patterns 37 Decorator Pattern Structure Component Operation() ConcreteComponent Operation() Decorator Operation() ConcreteDecoratorA Operation() AddedState ConcreteDecoratorB Operation() Addedbehavior

Design Patterns 38 Decorator Pattern Participants Component Define the interface for objects that can have responsibilities added to them dinamically Concrete Component Defines an object to which additional responsibilities can be attached Decorator Mantains a reference to a Component object and defines an interface that conforms to Component’s interface ConcreteDecorator Added responsibilities to the component

Design Patterns 39 Decorator Pattern Consequences More flexibility than static inheritance Avoids feature-laden classes high up in the hierarchy A decorator and its component are not identical Lots of little objects

Design Patterns 40 Example of Decorator Motivation If you have a TextView object that displays text in a Window TextView has no scroll bars by default TextView has no bord by default …

Design Patterns 41 Example of Decorator Structure aBorderDecorator component aScrollDecorator component aTextView

Design Patterns 42 Example of Decorator Structure VisualComponent Draw() TextView Draw() Decorator Draw() ScrollDecoratorBorderDecorator Draw() ScrollTo() ScrollPosition Draw() DrawBorder() BorderWidth

Design Patterns 43 Iterator Pattern Also know as Cursor Motivation Provide more way to access to the elements of an aggregate List Count() Append(Element) Remove(Element) … ListIterator First() Next() IsDone() CurrentItem Index

Design Patterns 44 Iterator Pattern Applicability Access an aggregate object’s contents Support multiple traversals of aggregate objects Provide an uniform interface

Design Patterns 45 Iterator Pattern Structure Aggregate CreateIterator() ConcreteAggregate CreateIterator() Iterator First() Next() IsDone() CurrentItem() ConcreteIterator Return new ConcreteIterator(This) Client

Design Patterns 46 Iterator Pattern Participants Iterator Defines interfaces for accessing elements ConcreteIterator Implements the Iterator interface Keeps track of the current position in the traversal of the aggregate Aggregate Defines an interface for creating an Iterator object Concrete Aggregate Implements the Iterator creation interface Return an instance of ConcreteIterator

Design Patterns 47 Iterator Pattern Consequences Simplify the Aggregate interface More that one traversal can be pending on an aggregate Variations in the traversal of an aggregate

Design Patterns 48 Patterns and Frameworks Design patterns are more abstract than frameworks Design patterns are smaller architectural elements than frameworks Design patterns are less specialized than frameworks Framework is executable software, design pattern represent knowledge about software Frameworks are the physical realization of one or more software pattern solutions,pattern are instructions for how to implement those solutions Set of cooperating classes that make up reusable design for a specific class of software. Provides architectural guidance by partitioning the design into abstract classes and defining their responsibilities and collaborations. A developer customizes a framework to a particular application by subclassing and composing instances of framework classes.

Design Patterns 49 Conclusions At present, the software community is using pattern largely for software architecture and design More recently the software community is using pattern also for software development processes and o organizations Several object-oriented software design notations/methods have added support for the modeling and representation of design patterns

Design Patterns 50 Night Patterns The coffee mug etched black inside Haunts the worn gray keys. The computer screen amused pearlwhite lights the developer’s hands And his night still life: pencils and books, scattered page of code circled and crossed with notes. Outside, along the river, white headlights flow, Red lights retreat.

Design Patterns 51 Night Patterns Inside the agile black box it waits- the Conjuring That lifts alive vined parts, Veins flowing in forces he imagines By circles and crosses, in dozing spells, In whitened warmth upon noon earth, In peach trees by the wall- It waits to pulse the pages Toward life,the patterns of night, to bring The quality,singing soft and hangign low. RICHARD GABRIEL

Design Patterns 52 Bibliography For the pattern catalogue: Erich Gamma, Richard Helm,Ralph Johnson,John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. ADDISON-WESLEY 1995 For the pattern origin: Cristopher Alexander. The Timeless Way of Building. Oxford Press 1979 For “Night Patterns”: James O.Coplien,Douglas C.Schmidt.Pattern Languages of Program Design. ADDISON- WESLEY 1995

Design Patterns 53 More Information Here you can find some example in Italian of design patterns. ml ml Here you can find some general information about patterns m m A complete Web site about pattern terns-intro.html terns-intro.html