CS212: Object Oriented Analysis and Design Lecture 37: Design Pattern.

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.
Lecture 9 Design Patterns CSCI – 3350 Software Engineering II Fall 2014 Bill Pine.
Object-Oriented Software Development CS 3331 Fall 2009.
CS590L - Lecture 6 1 CS590L Distributed Component Architecture References: - E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of.
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
(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.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
Design Patterns CS is not simply about programming
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 Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.
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.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CS 4240: Introduction to Design Patterns Readings: Chap. 5 of Design Patterns Explained Also, Chap. 6 and 7 Also, on-line info on Composite pattern (and.
Introduction to software design patterns For CSE 3902 By: Matt Boggus.
Object-Oriented Design Patterns CSC 335: Object-Oriented Programming and Design.
Design Patterns Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
CSE 332: Design Patterns (Part I) Introduction to Design Patterns Design patterns were mentioned several times so far –And the Singleton Pattern was discussed.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
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.
Programming in Java Unit 3. Learning outcome:  LO2:Be able to design Java solutions  LO3:Be able to implement Java solutions Assessment criteria: 
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Software Design 1.1 Tapestry classes -> STL l What’s the difference between tvector and vector  Safety and the kitchen sink What happens with t[21] on.
GRASP: Designing Objects with Responsibilities
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
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.
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.
ECE450S – Software Engineering II
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
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.
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Advanced Object-Oriented Design Patterns and Architectures Part One COEN396A John Xiao
Design Reuse Earlier we have covered the re-usable Architectural Styles as design patterns for High-Level Design. At mid-level and low-level, design patterns.
Design Patterns Introduction
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
From Use Cases to Implementation 1. Structural and Behavioral Aspects of Collaborations  Two aspects of Collaborations Structural – specifies the static.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
From Use Cases to Implementation 1. Mapping Requirements Directly to Design and Code  For many, if not most, of our requirements it is relatively easy.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
GRASP – Designing Objects with Responsibilities
Design Patterns: MORE Examples
Strategy Design Pattern
The Object-Oriented Thought Process Chapter 15
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Design Patterns Introduction
08/15/09 Design Patterns James Brucker.
DESIGNING YOUR SYSTEM.
The iterator and memento patterns
DESIGN PATTERNS : Introduction
Software Design Lecture : 39.
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Presentation transcript:

CS212: Object Oriented Analysis and Design Lecture 37: Design Pattern

Recap of Lecture UML Altogether Use case Class diagram Sequence diagram Activity diagram

Outline of Lecture 37 Design Pattern Pattern everywhere Pattern in computation Design pattern Iterator Patter Gang of Four Pattern

Pattern’s Everywhere Summer, Winter, Autumn, Spring: Climatic Pattern New Moon, Full Moon: Lunar Pattern Patterns in Nature

Pattern’s Everywhere Bhairavi, Malkosh, Hansadhwani: Musical Pattern Bibi #1, Hero #1, Jodi #1, … Bollywood Pattern Simple, Complex, Compound Sentences: Grammatical Pattern Patterns in Art / Humanities

Pattern’s Everywhere Unconditional Branch, Conditional Branch, Definite Loop, Indefinite Loop, Recursion: Programming Pattern Divide-and-Conquer, Greedy, Dynamic Programming, Branch- and-Bound: Algorithmic Pattern Factory, Iterator, Visitor, Singleton: Design Pattern Patterns in Computation

Architectural patterns Design patterns Code patterns (Idioms)‏

Architectural Patterns Architectural designs concern the overall structure of software systems Architectural designs cannot directly be programmed Form a basis for more detailed design While working out the high-level solutions to very large problems Architectural patterns are relevant Mar-15Software Engineering

Architectural Patterns Examples File Sharing Architecture Client/Server architecture n-Tiered Architecture Service Oriented Architecture (SOA) Mar-15Software Engineering

Design Patterns (DP) A design pattern Suggests a scheme for structuring the classes in a design solution Defines the interactions required among those classes Design pattern solutions are described in terms of Classes, their instances, their roles and collaborations. Mar-15Software Engineering

History of DP The concept of a "pattern": First expressed in Christopher Alexander's work A Pattern Language in 1977 (2543 patterns) In 1990: Gang of Four or "GoF" (Gamma, Helm, Johnson, Vlissides) compile a catalog of design patterns Design pattern: a solution to a common software problem in a certain context Example: Iterator pattern The Iterator pattern defines an interface that declares methods for sequentially accessing the objects in a collection. Mar-15Software Engineering

Idioms Idioms are a low-level patterns: Programming language-specific Describes how to implement a solution to a particular problem using a given programming language Mar-15Software Engineering

Idioms Idioms in English language: A group of words that has meaning different from a simple juxtaposition of the meanings of the individual words Example: “Raining cats and dogs” A C idiom: for(i=0;i<1000;i++) { } Mar-15Software Engineering

Patterns versus Idioms A pattern: Describes a recurring problem Describes a core solution Is capable of generating many distinct designs An Idiom though describes a recurring problem is more restricted: Provides a specific solution, with fewer variations Applies only to a narrow context e.g., the C++ language Mar-15Software Engineering

Antipattern If a pattern represents a best practice: represents lessons learned from a bad design Antipatterns help to recognise deceptive solutions: appear attractive at first, but turn out to be a liability later Mar-15Software Engineering

Patterns versus Algorithms Are patterns and algorithms identical concepts? After all, both target to provide reusable solutions to problems! Algorithms primarily focus on solving problems with reduced space and/or time requirements: Patterns focus on understandability and maintainability of design and easier development Mar-15Software Engineering

What is a DP? A Design Pattern describes a problem Occurring over and over again (in software engineering) describes the solution Sufficiently generic Applicable in a wide variety of contexts. Mar-15Software Engineering Recurring Solution to a Recurring Problem

Essential Elements of a DP 1.Pattern Name: Descriptor for a design problem, its solutions, and their consequences. 2.Problem: Where to apply the pattern and its associated context. 3.Solution: Elements that make up the design, their relationships, responsibilities, and collaborations. 4.Consequences: Results and trade-offs in applying the pattern. Mar-15Software Engineering

Example Pattern Pattern Name Iterator Problem How to serve Patients at a Doctor’s Clinic Solution Front-desk manages the order for patients to be called By Appointment By Order of Arrival By Extending Gratitude By Exception … Consequences Patient Satisfaction Clinic’s Efficiency Doctor’s Productivity Mar-15Software Engineering

Describing a Design Pattern Every Design Pattern is Described in a specific format We first illustrate an example before presenting the generic format for description Example of Iterator Pattern Mar-15Software Engineering

Mar-15 Iterator Pattern Pattern Name and Classification: Iterator Behavioral Intent Provide a way to access the elements of an aggregate object (container) sequentially without exposing its underlying representation. CONTAINERS Array Vector List Stack Queue Tree SEQUENTIAL Forward Backward Bidirectional Random ACCESS Read Write Read-Write Software Engineering

Mar-15 Iterator Pattern Also Known As Cursor Motivation An aggregate object (list) should have a way to access its elements without exposing its internal structure. There is a need to traverse the list in different ways, depending on a specific task. Multiple traversals may be pending on the same list. The key idea in this pattern is to take the responsibility for access and traversal out of the list object and put it into an iterator object. Software Engineering

Mar-15 Iterator Pattern Motivation Software Engineering List Count() Append(Element) Remove(Element) … ListIterator First() Next() IsDone() CurrentItem() index list

Mar-15 Iterator Pattern Applicability Access an aggregate object's contents without exposing its internal representation. Support multiple traversals of aggregate objects. Provide a uniform interface for traversing different aggregate structures (that is, to support polymorphic iteration). Software Engineering

Mar-15 Iterator Pattern Participants Iterator defines an interface for accessing and traversing 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. ConcreteAggregate implements the Iterator creation interface to return an instance of the proper ConcreteIterator. Software Engineering

Mar-15 Iterator Pattern Collaborations A ConcreteIterator keeps track of the current object in the aggregate and can compute the succeeding object in the traversal. Consequences It supports variations in the traversal of an aggregate. Iterators simplify the Aggregate interface. More than one traversal can be pending on an aggregate. Software Engineering

Mar-15 Iterator Pattern: Implementation Who controls the iteration? External Iteration Internal Iteration Who defines the traversal algorithm? How robust is the iterator? What happens if items are inserted / deleted? Additional Iterator operations Using polymorphic iterators in C++. allocated dynamically by a factory method the client is responsible for deleting them Iterators may have privileged access friend class Iterators for composites Null iterators Software Engineering

Describing a Design Pattern Motivation A scenario that illustrates a design problem and how the class and object structures in the pattern solve the problem. Applicability What are the situations in which the design pattern can be applied? What are examples of poor designs that the pattern can address? How can you recognize these situations? Mar-15Software Engineering

Describing a Design Pattern Structure A graphical representation of the classes in the pattern using a notation based on the Object Modeling Technique (OMT) – specifically UML. Participants The classes and/or objects participating in the design pattern and their responsibilities. Collaborations How the participants collaborate to carry out their responsibilities? Mar-15Software Engineering

Describing a Design Pattern Consequences How does the pattern support its objectives? What are the trade-offs and results of using the pattern? What aspect of system structure does can be varied independently? Implementation What pitfalls, hints, or techniques should you be aware of when implementing the pattern? Are there language-specific issues? Mar-15Software Engineering

Describing a Design Pattern Sample Code Code fragments to implement the pattern in specific language (C++ or C# or Java). Known Uses Examples of the pattern found in real systems. Related Patterns What design patterns are closely related to this one? What are the important differences? With which other patterns should this one be used? Mar-15Software Engineering

Mar-15 Catalogue of Design Patterns (GoF) Software Engineering

Understanding a DP Intent Problem Discussion Structure Example Check list Rules of thumb

Thank you Next Lecture: Design Pattern