Design Patterns Ref : Chapter 15 Bennett et al. useful groups of collaborating classes that provide a solution to commonly occuring problems. provide.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 8 Slide 1 System modeling 2.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Plab – Tirgul 12 Design Patterns
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 8 Slide 1 System models.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
© Bennett, McRobb and Farmer Design Patterns Based on Chapter 15 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design Using.
Design Patterns CS is not simply about programming
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
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.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Modified from Sommerville’s originalsSoftware Engineering, 7th edition. Chapter 8 Slide 1 System models.
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
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.
1 PH Chapter 1 (pp. 1-10) GoF Composite Pattern (pp ) PH Ch 2 through Fundamentals (pp ) Presentation by Julie Betlach 5/28/2009.
Refining the Requirements Model
Software Engineering Muhammad Fahad Khan
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse.
Design Patterns.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions of systems whose requirements are being.
Chapter 4 System Models A description of the various models that can be used to specify software systems.
System models Abstract descriptions of systems whose requirements are being analysed Abstract descriptions of systems whose requirements are being analysed.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
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.
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.
1 Design Patterns Lecture 5 SD Outline Definition Design Patterns in Engineering Design patterns characteristic Types of Patterns Benefits of using.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Design engineering Vilnius The goal of design engineering is to produce a model that exhibits: firmness – a program should not have bugs that inhibit.
Patterns and Reuse. Patterns Reuse of Analysis and Design.
Chapter 7 System models.
System models l Abstract descriptions of systems whose requirements are being analysed.
Modified by Juan M. Gomez Software Engineering, 6th edition. Chapter 7 Slide 1 Chapter 7 System Models.
Sommerville 2004,Mejia-Alvarez 2009Software Engineering, 7th edition. Chapter 8 Slide 1 System models.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CSE 432: Design Patterns Introduction What’s a Pattern? What’s an Idiom? According to Alexander, a pattern: –Describes a recurring problem –Describes the.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Structural Design Patterns
ECE450S – Software Engineering II
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Advanced Object-Oriented Design Patterns and Architectures Part One COEN396A John Xiao
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.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Chapter 16 UML Class Diagrams 1CS6359 Fall 2012 John Cole.
Advanced Object-oriented Design Patterns Creational Design Patterns.
1 Here are some quotations to get an overview of the kinds of issues of interest.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
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.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Chapter 10 Design Patterns.
MPCS – Advanced java Programming
Behavioral Design Patterns
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering Lecture 7 - Design Patterns
CS 350 – Software Design Singleton – Chapter 21
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Presentation transcript:

Design Patterns Ref : Chapter 15 Bennett et al

useful groups of collaborating classes that provide a solution to commonly occuring problems. provide a means for capturing knowledge about problems and successful solutions.

vs Patterns More abstract that frameworks description of the way a type of problem can be solved, but not in themselves solutions, as they can’t be directly implemented. They are more primitive than frameworks Frameworks Frameworks (e.g..net framework, xna) Partially completed software systems that may be targeted at a specific type of application. Re-usable mini architectures. Can be customised by specialisation of classes, add-in operations and classes.

A Pattern Catalogue Lists commonly used design patterns using pattern templates Problem – describes the problem Context – describes how it occurs Forces – constraints or issues that must be addressed by solution Solution – describes solution approaches Code fragments – show how the solution can be implemented in code E.g. see

Example Whole-part pattern – specifically supports aggregation and composition relationships in UML (see page 334). Gang of Four (GOF) developed sets of design patterns and guidelines for their use. (Gamma Helm Johnston and Vlissides) Client Whole Service_1 Service_2 Part 2 Service_b1 Service_b2 Part 1 Service_a1 Service a_2

Scope of a pattern: class level (static- relationships) or object level (dynamic) Patterns are based on principles of good design: maximise encapsulation/ using composition – Maintainability – Extensibility – Restructuring – portability

3 Types of Design Pattern (GOF) Creational –concerned with how objects are constructed Structural- address issues concerned with the way classes and objects are organised. Behavioural- describe how objects communicate See c# examples on...

Example Creational Pattern:Singleton Problem: Ensure a class has only one instance and provide a global point of access to it. e.g. In water safety we only want one Water safety Authority object, which needs global access. Solution: Make the constructor private Have a get_instance method to either create the object or return the object reference. Class singleton _uniqueinstance -singletondata +get_instance +getdata -singleton

C# implementation class Singleton { private static Singleton _instance; // Constructor is 'protected‘ not public as usual protected Singleton() { } public static Singleton Instance() { if (_instance == null) { _instance = new Singleton(); } return _instance; } Note this is not thread safe.

Structural Pattern example: Composite Problem: to represent whole-part hierarchies so that both offer the same interface to client objects. Context : Both composite and component objects exist and should be treated in the same way. Solution : Combine inheritance and aggregation hierarchies. Compose objects into tree structures to represent part-whole hierarchies.

See figs 15.10, Bennett et al SoundClip +play() Advert Advert sequence MediaClipCollection[n] +play() +addclip() +=removeclip() +getchild() +changesequence() Media Clip _uniqueinstance -singletondata +play() VideoClip +play() * ordered For all m in MediaClipCollection m.play()

Source :

Example Behavioural Pattern : state Problem: operations done differently on an object dependent on its state. Description: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class. Create additional classes, one for each state so that each holds a state-sepcific version of the operation. ‘pure state’ classes contain no attributes, just redefinitions of operations. This should only be used for objects with significant state- dependent behaviour, as there is a big code overhead with the extra classes.

Source :

An object has complex behaviour which is dependent on its STATE The original object delegates reponsibility to the appropriate state object A changestate() method is sent to the parent who invokes a nextstate method.

Example Behavioural Pattern 2 : Command An object is used to encapsulate all the information needed to call a method at a later time:- the method name, the object that owns the method and values for the method parameters. – client instantiates the command object and provides the information required to call the method at a later time. – invoker decides when the method should be called. – receiver is an instance of the class that contains the method's code. makes it easier to construct general components that need to delegate, sequence or execute method calls at a time of their choosing without the need to know the owner of the method or the method parameters. Good for allowing undos.

How to use design Patterns NOT for the sake of it – there are many examples of badly used patterns. Analyse problem and context Ensure that you really understand patterns Find a pattern that addresses a similar problem, read and study it and determine whether it gives you a better solution Check it there is a simpler solution Check that the context of the pattern similar to your problem Make sure the consequences of using the pattern are acceptable. Examine sample code. Apply and refine.

A pattern.. (hillside.net) solves a problem: Patterns capture solutions, not just abstract principles or strategies. is a proven concept: Patterns capture solutions with a track record, not theories or speculation. describes a relationship: Patterns don't just describe modules, but describe deeper system structures and mechanisms. has a significant human component (minimize human intervention). All software serves human comfort or quality of life; the best patterns explicitly appeal to aesthetics and utility.

A pattern language defines a collection of patterns and the rules to combine them into an architectural style. Pattern languages describe software frameworks or families of related systems. The solution isn't obvious: Many problem-solving techniques (such as software design paradigms or methods) try to derive solutions from first principles. The best patterns generate a solution to a problem indirectly--a necessary approach for the most difficult problems of design.

References Chapter 15 Bennett et al explains patterns well and has some good examples. Hillside.net has lots of useful links, including a link to several pattern catalogues. Dofactory.com has lots of c# examplesand skeletal code.