1 Design Patterns Lecture 5 SD3043. 2 Outline Definition Design Patterns in Engineering Design patterns characteristic Types of Patterns Benefits of using.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Design Patterns based on book of Gang of Four (GoF) Erich Gamma, Richard Helm, Ralph Johnson, and John VlissidesGang of Four (GoF) Elements of Reusable.
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.
Lecture 9 Design Patterns CSCI – 3350 Software Engineering II Fall 2014 Bill Pine.
18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
CS590L - Lecture 6 1 CS590L Distributed Component Architecture References: - E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of.
Design patterns Glenn D. Blank. Definitions A pattern is a recurring solution to a standard problem, in a context. Christopher Alexander, a professor.
Design Patterns Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
(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.
© Bennett, McRobb and Farmer Design Patterns Based on Chapter 15 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design Using.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
Design Patterns CS is not simply about programming
Copyright © Active Frameworks, Inc.. - All Rights Reserved - V2.0 Introduction - Page L1-1 PS95&96-MEF-L1-1 Dr. M.E. Fayad Creationa l Paradigm.
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 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 ( ) ( ) ( )
Design Patterns Ref : Chapter 15 Bennett et al. useful groups of collaborating classes that provide a solution to commonly occuring problems. provide.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Larman, chapters 25 and 26 CSE432 Object-Oriented Software Engineering Glenn D. Blank, Lehigh University Pure Fabrication and “Gang of Four” Design Patterns.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
Design Patterns Trends and Case Study John Hurst June 2005.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
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.
Pure Fabrication and “Gang of Four” Design Patterns
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
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.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
CS616: Software Engineering Spring 2009 Design Patterns Sami Taha.
IM 2042 – Information Systems Modeling and Design Topic 4 – Refining the Requirements Model. Design Patterns Based on chapters 8 and 15 of Bennett, McRobb.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
1 Design Patterns G.Ramesh Babu. © Bennett, McRobb and Farmer In This Lecture You Will Learn:  What types of patterns have been identified in.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
The Object-Oriented Thought Process Chapter 15
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
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Informatics 122 Software Design II
Presentation transcript:

1 Design Patterns Lecture 5 SD3043

2 Outline Definition Design Patterns in Engineering Design patterns characteristic Types of Patterns Benefits of using Patterns

3 Patterns Are problem-centred, not solution- centred Are Discovered, not invented - they already exist Complement existing techniques and do not replace them Capture and communicate “best practice” and expertise

4 Application of Patterns Applied to software design since early 90’s Now used in in: –Project management –Organisation structures –Requirements analysis –System design –General modelling approaches –Programming – (called idioms) –...

5 Origin of Patterns Christopher Alexander applied patterns to architecture in the mid-70s His book “A Pattern Language” is a catalogue of 253 patterns These document how to construct rooms, buildings and whole communities that people would like to live and work in

6 Software Pattern Definitions A pattern is proven solution to a problem that recurs in a particular context. »A useful discussion of the possible definitions of a pattern can be found at

7 Patterns in engineering How do other engineers find and use patterns? –Mature engineering disciplines have handbooks describing successful solutions to known problems –Automobile designers don't design cars from scratch using the laws of physics –Instead, they reuse standard designs with successful track records, learning from experience –Should software engineers make use of patterns? Why? Developing software from scratch is also expensive –Patterns support reuse of software architecture and design

8 The “gang of four” (GoF) Erich Gamma, Richard Helm, Ralph Johnson & John Vlissides (Addison-Wesley, 1995) –Design Patterns book catalogs 23 different patterns as solutions to different classes of problems, in C++ & Smalltalkcatalogs 23 different patterns –The problems and solutions are broadly applicable, used by many people over many years –Example - Command Pattern – –Why is it useful to learn about this pattern? Patterns suggest opportunities for reuse in analysis, design and programming –

9 Example - Observer patternObserver pattern Intent: –Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically Used in Model-View-Controller framework –Model is problem domain –View is windowing system –Controller is mouse/keyboard control How can Observer pattern be used in other applications? JDK’s Abstract Window Toolkit (listeners) Java’s Thread monitors, notify(), etc.

10 Documenting Design Patterns -1 Pattern Name and Classification: A descriptive and unique name that helps in identifying and referring to the pattern. Intent: A description of the goal behind the pattern and the reason for using it. Also Known As: Other names for the pattern. Motivation (Forces): A scenario consisting of a problem and a context in which this pattern can be used. Applicability: Situations in which this pattern is usable; the context for the pattern. Structure: A graphical representation of the pattern. Class diagrams and Interaction diagrams may be used for this purpose. Class diagramsInteraction diagrams

11 Documenting Design Patterns - 2 Participants: A listing of the classes and objects used in the pattern and their roles in the design. Collaboration: A description of how classes and objects used in the pattern interact with each other. Consequences: A description of the results, side effects, and trade offs caused by using the pattern. Implementation: A description of an implementation of the pattern; the solution part of the pattern. Sample Code: An illustration of how the pattern can be used in a programming language Known Uses: Examples of real usages of the pattern. Related Patterns: Other patterns that have some relationship with the pattern; discussion of the differences between the pattern and similar patterns

12 Three Types of Patterns Creational patterns: –Deal with initializing and configuring classes and objects Structural patterns: –Deal with decoupling interface and implementation of classes and objects –Composition of classes or objects Behavioral patterns: –Deal with dynamic interactions among societies of classes and objects –How they distribute responsibility

13 Creational Patterns Concerned with the construction of object instances Separate the operation of an application from how its objects are created Gives the designer considerable flexibility in configuring all aspects of object creation

14 Creational Patterns: Singleton How does one ensure that only one instance of the company class is created? Company companyName companyAddress companyRegistrationNumber getCompanyDetails ()

15 Creational Patterns: Singleton Solution – restrict access to the constructor! Company - companyInstance - companyName - companyAddress - companyRegistrationNumber + getCompanyInstance() + getCompanyDetails() Class-scope (or static) attribute (or static) operation - Company() Private constructor The use of class-scope operations allows global access Class-scope

16 Creational Patterns: Singleton Company - companyInstance - companyName - companyAddress + getCompanyInstance() + getCompanyDetails() - Company() + getCompanyDetails():String - UkCompany():UkCompany - companyRegistrationNumber UKCompany + getCompanyDetails():String - USACompany():USACompany - companyRegistrationNumber USACompany + getCompanyDetails():String - FrenchCompany():FrenchCompany - companyRegistrationNumber FrenchCompany The attribute companyRegistrationNumber has been moved to the subclasses where it is defined differently in each. The operation getCompanyDetails() has been moved to the subclasses where it is polymorphically redefined in each. Different subclasses of Company can be instantiated as needed, depending on run-time circumstances

17 Creational Patterns: Singleton + getInstance() Singleton - uniqueInstance - singletonData + getSingletonData() + singletonOperation() - Singleton() Holds object identifier for the Singleton instance Returns object identifier for the unique instance Private constructor — only accessible via getInstance() General form of Singleton pattern

18 Creational Patterns Abstract Factory: –Factory for building related objects Builder: –Factory for building complex objects incrementally Factory Method: –Method in a derived class creates associates Prototype: –Factory for cloning new instances from a prototype Singleton: –Factory for a singular (sole) instance

19 Structural Patterns Concerned with the way in which classes and objects are organized Offer effective ways of using object- oriented constructs such as inheritance, aggregation and composition to satisfy particular requirements

20 Structural Patterns: Composite MediaClip play() VideoClip play() SoundClip play() How can we present the same interface for a media clip whether it is composite or not?

21 Structural Patterns: Composite Delegates to the play() operation in the components. play() is polymorphically redefined VideoClip play() SoundClip play() AdSequence play() addClip() removeClip() getChild() * * 1 How can we incorporate composite structures?

22 Composite applied Collection of MediaClip object identifiers for all m in mediaClipCollection m.play() Delegates to the play() operation in the components. play() is polymorphically redefined AdSequence mediaClipCollection play() addClip() removeClip() getChild() changeSequence() * 1 MediaClip play() addClip() removeClip() getChild() VideoClip play() SoundClip play() Advert {ordered}

23 Composite Pattern General Form Collection of Component object identifiers for all c in componentCollection c.anOperation() anOperation() is polymorphically redefined Composite componentCollection anOperation() addComponent() removeComponent() getChild() * 1 Component anOperation() addComponent() removeComponent() getChild() Leaf anOperation() OtherLeaf anOperation() Client

24 Structural patterns - example Describe ways to assemble objects to realize new functionality –Added flexibility inherent in object composition due to ability to change composition at run-time –not possible with static class composition Example: ProxyProxy –Proxy: acts as convenient surrogate or placeholder for another object. Remote Proxy: local representative for object in a different address space Virtual Proxy: represent large object that should be loaded on demand Protected Proxy: protect access to the original object

25 Example – Decorator Pattern er/ch03.pdf

26 Structural Patterns Adapter: –Translator adapts a server interface for a client Bridge: –Abstraction for binding one of many implementations Composite: –Structure for building recursive aggregations Decorator: –Decorator extends an object transparently Facade: –Simplifies the interface for a subsystem Flyweight: –Many fine-grained objects shared efficiently. Proxy: –One object approximates another

27 Behavioural Patterns Address the problems that arise when assigning responsibilities to classes and when designing algorithms Suggest particular static relationships between objects and classes and also describe how the objects communicate

28 Behavioral Patterns Chain of Responsibility: –Request delegated to the responsible service provider Command: –Request or Action is first-class object, hence re-storable Iterator: –Aggregate and access elements sequentially Interpreter: –Language interpreter for a small grammar Mediator: –Coordinates interactions between its associates Memento: –Snapshot captures and restores object states privately

29 Behavioral Patterns (cont.) Observer: –Dependents update automatically when subject changes State: –Object whose behavior depends on its state Strategy: –Abstraction for selecting one of many algorithms Template Method: –Algorithm with some steps supplied by a derived class Visitor: –Operations applied to elements of a heterogeneous object structure

30 Patterns in software libraries AWT and Swing use Observer pattern Iterator pattern in C++ template library & JDK Façade pattern used in many student- oriented libraries to simplify more complicated libraries! Bridge and other patterns recurs in middleware for distributed computing frameworks …

31 More software patterns Design patterns –idioms (low level, C++): Jim Coplein, Scott Meyers I.e., when should you define a virtual destructor? –design (micro-architectures) [Gamma-GoF] –architectural (systems design): layers, reflection, brokerarchitectural Java Enterprise Design Patterns (distributed transactions and databases)Java Enterprise Design Patterns Analysis patterns (recurring & reusable analysis models, from various domains, i.e., accounting, financial trading, health care)Analysis patterns Process patterns (software process & organization)Process patterns

32 Benefits of Design Patterns Design patterns enable large-scale reuse of software architectures and also help document systems Patterns explicitly capture expert knowledge and design tradeoffs and make it more widely available Patterns help improve developer communication Pattern names form a common vocabulary

33 Before Using Patterns Before using a pattern to resolve the problem ask –Is there a pattern that addresses a similar problem? –Does the pattern trigger an alternative solution that may be more acceptable? –Is there a simpler solution? Patterns should not be used just for the sake of it

34 Before Using Patterns –Is the context of the pattern consistent with that of the problem? –Are the consequences of using the pattern acceptable? –Are constraints imposed by the software environment that would conflict with the use of the pattern?

35 Web Resources Java Enterprise Design Patterns mlJava Enterprise Design Patterns ml Yahoo Design Pattern Library Design Patterns tterns01/home.htmlhttp:// tterns01/home.html