1 Design Patterns G.Ramesh Babu. © Bennett, McRobb and Farmer 2002 2 In This Lecture You Will Learn:  What types of patterns have been identified in.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
Plab – Tirgul 12 Design Patterns
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
Patterns Lecture 2. Singleton Ensure a class only has one instance, and provide a global point of access to it.
© 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
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
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.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Object Oriented Software Development
Design Patterns Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
Design Patterns.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
An Introduction to Software Architecture
CSE 303 – Software Design and Architecture
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.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Unified Modeling Language, Version 2.0
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.
Patterns and Reuse. Patterns Reuse of Analysis and Design.
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
GRASP: Designing Objects with Responsibilities
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Introduction to Design Patterns Part 1. © Lethbridge/Laganière 2001 Chapter 6: Using design patterns2 Patterns - Architectural Architectural Patterns:
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
What is a pattern? Alexander's definition- Each pattern describes a problem which occurs over and over again in our environment, and then describes the.
IM 2042 – Information Systems Modeling and Design Topic 4 – Refining the Requirements Model. Design Patterns Based on chapters 8 and 15 of Bennett, McRobb.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
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.
1 Unified Modeling Language, Version 2.0 Chapter 2.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
Basic Characteristics of Object-Oriented Systems
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Patterns in programming
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Business System Development
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Factory Patterns 1.
Introduction to Design Patterns
Design Patterns.
OOP What is problem? Solution? OOP
Presented by Igor Ivković
Software Engineering Lecture 7 - Design Patterns
Introduction to Design Patterns Part 1
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Presented by Igor Ivković
Presentation transcript:

1 Design Patterns G.Ramesh Babu

© Bennett, McRobb and Farmer In This Lecture You Will Learn:  What types of patterns have been identified in software development  How to apply design patterns during software development  The benefits and difficulties that may arise when using patterns

© Bennett, McRobb and Farmer Patterns vs. Frameworks n Frameworks are partially completed software systems that may be targeted at a specified type of application n However patterns –are more abstract and general than frameworks –cannot be directly implemented in a particular software environment –are more primitive than frameworks

© Bennett, McRobb and Farmer Catalogues & Languages n A pattern catalogue is a group of patterns that are related to some extent and may be used together or independently of each other n The patterns in a pattern language are more closely related, and work together to solve problems in a specific domain

© Bennett, McRobb and Farmer Key Principles n Key principles that underlie patterns –abstraction –encapsulation –information hiding –modularization –separation of concerns

© Bennett, McRobb and Farmer Key Principles –Coupling and cohesion –Sufficiency –Completeness and primitiveness –Separation of policy and implementation –Separation of interface and implementation –Single point of reference –Divide and conquer Buschmann et al. (1996)

© Bennett, McRobb and Farmer Non-functional Properties n Buschmann et al. (1996) identify the important non-functional properties of a software architecture n changeability n interoperability n efficiency n reliability n testability n reusability

© Bennett, McRobb and Farmer Pattern Template n Name—meaningful that reflects the knowledge embodied by the pattern n Problem—description of the problem that the pattern addresses (the intent of the pattern). n Context—represents the circumstances or precon- ditions under which it can occur. n Forces—embodied in a pattern are the constraints or issues that must be addressed by the solution n Solution—description of the static and dynamic relationships among the components of the pattern

© Bennett, McRobb and Farmer Other Aspects of Templates n An example of the use of a pattern that serves as a guide to its application n The context that results from the use of the pattern n The rationale that justifies the chosen solution n Related patterns

© Bennett, McRobb and Farmer Other aspects of Templates n Known uses of the pattern that validate it (Some suggest that until the problem and its solution have been used successfully at least three times—the rule of three—they should not be considered as a pattern) n A list of aliases for the pattern (‘also known as’ or AKA) n Sample program code and implementation details (commonly used languages include C++, Java and Smalltalk)

© Bennett, McRobb and Farmer GOF Design Patterns n Catalogue of 23 design patterns presented by Gamma et al. (1995) patterns known as Gang of Four—hence GOF Patterns n Classifies patterns as creational, structural or behavioural n Typically address issues concerning changeability, and involve several different aspects: maintainability, extensibility, restructuring and portability

© Bennett, McRobb and Farmer Creational Patterns n Concerned with the construction of object instances n Separate the operation of an application from how its objects are created n Gives the designer considerable flexibility in configuring all aspects of object creation

© Bennett, McRobb and Farmer Creational Patterns: Singleton n How does one ensure that only one instance of the company class is created? Company companyName companyAddress companyRegistrationNumber getCompanyDetails( )

© Bennett, McRobb and Farmer Creational Patterns: Singleton n 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

© Bennett, McRobb and Farmer 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

© Bennett, McRobb and Farmer 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

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

© Bennett, McRobb and Farmer 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?

© Bennett, McRobb and Farmer 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?

© Bennett, McRobb and Farmer Composite applied to Agate 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}

© Bennett, McRobb and Farmer Composite Pattern General Form anOperation( ) addComponent( ) removeComponent( ) getChild( ) Collection of Component object identifiers for all c in componentCollection c.anOperation() Delegates to the anOperation() operation in the components. anOperation() is polymorphically redefined Composite componentCollection anOperation( ) addComponent( ) removeComponent( ) getChild( ) * 1 Component Leaf anOperation( ) OtherLeaf anOperation( ) Client {Ordered}

© Bennett, McRobb and Farmer Behavioural Patterns n Address the problems that arise when assigning responsibilities to classes and when designing algorithms n Suggest particular static relationships between objects and classes and also describe how the objects communicate

© Bennett, McRobb and Farmer Behavioural Patterns: State Consider the class Campaign. It has four states— Commissioned, Active, Completed and Paid A Campaign object has different behaviour depending upon which state it occupies n Operations have case statements giving this alternative behaviour n The class factored into separate components —one for each of its states

© Bennett, McRobb and Farmer Behavioural Patterns: State Contains the object identifier of the current state object CampaignState addAdvert( ) calcCosts( ) Commissioned addAdvert( ) calcCosts( ) Campaign currentStateIdentifier addAdvert( ) changeState( ) calcCosts( ) Active addAdvert( ) calcCosts( ) Completed addAdvert( ) calcCosts( ) Paid addAdvert( ) calcCosts( ) State pattern applied to the class Campaign

© Bennett, McRobb and Farmer Behavioural Patterns: State A:Campaign B D:Campaign C:Campaign :Commissioned :Active :Completed :Paid E:Campaign F Some State pattern objects for Agate – note that there are 6 Campaign objects sharing the four State objects.

© Bennett, McRobb and Farmer General form of State Pattern State operation( ) ConcreteStateA operation( ) ConcreteStateB operation( ) Context operation( )

© Bennett, McRobb and Farmer Before Using Patterns n 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

© Bennett, McRobb and Farmer Before Using Patterns –Is the context of the pattern consistent with that of the problem? –Are the consequences of using the pattern acceptable? –Are there constraints imposed by the software environment that would conflict with the use of the pattern?

© Bennett, McRobb and Farmer Using Patterns n After selecting a suitable pattern 1.Read the pattern to get a complete overview 2.Study the Structure, Participants and Collaborations of the pattern in detail 3.Examine the Sample Code to see an example of the pattern in use

© Bennett, McRobb and Farmer Using Patterns 4.Choose names for the pattern’s participants (i.e. classes) that are meaningful to the application 5.Define the classes 6.Choose application specific names for the operations 7.Implement operations that perform the responsibilities and collaborations in the pattern

© Bennett, McRobb and Farmer Summary In this lecture you have learned about:  What types of patterns have been identified in software development  How to apply design patterns during software development  The benefits and difficulties that may arise when using patterns

© Bennett, McRobb and Farmer References n Gamma et al. (1995) (For full bibliographic details, see Bennett, McRobb and Farmer)