June 26, 20151 Design Patterns  What is a Design Pattern -- Each pattern describes a problem which occurs over and over again in our environment, and.

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

Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Creational Patterns - Page L4-1 PS95&96-MEF-L11-1 Dr. M.E. Fayad Creationa l Paradigm.
Plab – Tirgul 12 Design Patterns
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
5/08 What is a Design Pattern „Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
DESIGN PATTERNS Redesigning Applications And
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
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.
UML - Patterns 1 Design Patterns. UML - Patterns 2 Becoming Good OO Developers Developing good OO Software is hard Takes a lot of time to take advantage.
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.
GoF: Document Editor Example Rebecca Miller-Webster.
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 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 VIII Chain of Responsibility, Strategy, State.
Design Pattern Dr. Zhen Jiang West Chester University url:
CSC 480 Software Engineering Design With Patterns.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Design Patterns Introduction
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
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.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
CS 5150 Software Engineering Lecture 16 Program Design 3.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
The State Design Pattern A behavioral design pattern. Shivraj Persaud
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Overview of Behavioral Patterns ©SoftMoore ConsultingSlide 1.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Builder Introduction. Intent Separate the construction of a complex object from its representation so that the same construction process can create different.
Review of last class. Design patterns CreationalStructuralBehavioral Abstract Factory Builder Factory Singleton etc. Adapter Bridge Composite Decorator.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Chapter 10 Design Patterns.
Software Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
Chapter 8, Design Patterns Builder
Design Patterns with C# (and Food!)
object oriented Principles of software design
What is a Design Pattern
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
CSC 480 Software Engineering
UNIT-III Creational Patterns UNIT-III.
Lesson 5: More on Creational Patterns
Creational Patterns.
Informatics 122 Software Design II
CSC 480 Software Engineering
Presentation transcript:

June 26, Design Patterns  What is a Design Pattern -- Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice(by Christopher Alexander)  Essential elements of a Design Pattern - pattern name - problem - solution - consequence

June 26, Classification of design pattern  According to its purpose -- Creational Factory Method, Abstract Factory, Builder, Prototype,Singleton -- Structural Adapter, Bridge, Composite, Decorator, Façade, Flyweight, Proxy -- Behavioral Interpreter, Template Method, Chain of Responsibility, command, Iterator, Mediator, Memento, Observer, State, Strategy, Visitor

June 26, Classification of design pattern(continued)  According to its scope class -- class Factory Method, Adapter(class), Interpreter, Template Method Object -- Object The rest of the patterns

June 26, Patterns with possible use in framework  Creational Patterns including Abstract Factory, Builder, Factory Method and Prototype  Behavioral Pattern Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor Notes: Factory Method and Template Method are class patterns

June 26, Abstract Factory Object Creational Abstract Factory Object Creational  Intent Provide an interface for creating families of related or dependent objects without specifying their concrete class  Motivation Consider a user interface toolkit that supports multiple look-and- feel standards, such as Motif and Presentation Manager. Different look- and-feels define different appearances and behaviors for user interface “widgets” like scroll bars, windows, and buttons. To be portable across look-and-feel standards, an application should not hard-code its widgets for a particular look-and-feel. Instantiating look- and-feel specific classes of widgets throughout the application makes it hard to change the look-and- feel later

June 26, Window Client MOtifWindowPMWindow ScrollBar MotifScorllBarPMScrollBar WidgetFactory createScrollBar() CreateWindow() MotifWidgetFactory PMWidgetFactory createScrollBar() CreateWindow() createScrollBar() CreateWindow()

June 26,  Structure

June 26,  Collaborations -- Normally a single instance of a ConcreteFactory class is created at run-time. This concrete factory creates product objects having a particular implementation. To create different product objects, clients should use a different concrete factory -- Normally a single instance of a ConcreteFactory class is created at run-time. This concrete factory creates product objects having a particular implementation. To create different product objects, clients should use a different concrete factory -- AbstractFactory defers creation of product objects to its -- AbstractFactory defers creation of product objects to its ConcreteFactory subclass ConcreteFactory subclass

June 26, Builder -- Object Creational  Intent -- Separate the construction of a complex object from its representation so that the same construction process can create different representation  Motivation -- A reader for the RTF(Rich Text Format) document exchange format should be able to convert RTF to many text formats. The reader might convert RTF documents into plain ASCII text or into a text widget that can be edited interactively. The problem, however, is that the number of possible conversions is open-ended. So it should be easy to add a new conversion without modifying the reader.

June 26, ConvertCccharacter(char) GetASCIITEXT() ASCIIConverter TeXConverter ConvertCccharacter(char) convertFontChange(Font) convertParagraph() GetTeXtext() TeXText ASCIIText TexWidget While(t=get the next token{ Switch t.Type{ CHAR: Builder->ConvertCharacter(t.Char) FONT: Builder->ConvertFontChange(t.Font) PARA: Biolder->convertParagraph() } TexWidgetConverter ConvertCccharacter(char) convertFontChange(Font) convertParagraph() GetTextWidget() ConvertCccharacter(char) convertFontChange(Font) convertParagraph() TextConverter builders RTFReader ParseRTF() builder

June 26,  Structure

June 26,  Collaborations -- The client creates the Director object and configures it with the desired Builder object -- Director notifies the builder whenever a part of the product should be built -- The client retrieves the product from the builder

June 26, Factory Method Class Creational Factory Method Class Creational  Intent Define an interface for creating an object, but let subclass decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses  Motivation Frameworks use abstract classes to define and maintain relationships between objects. A framework is often responsible for creating these objects as well. Consider a framework for applications that can present multiple documents to the user. Tow key abstractions in this framework are the classes Application and Document. Both classes are abstract,and clients have to subclass them to realize their application-specific implementations. To create a drawing application,for example,we define the class DrawingApplciation and DrawingDocument. The Application class is responsible for managing Documents and will create them as required-when when the user selects Open or New from a menu, for example.

June 26, MyDocument Document Open() Close(0 Save() Revert() createDocument() NewDocument() openDocument() Application createDocument() MyApplication Document* doc= createDocument(); Docs.Add(doc); Doc->open() Return new MyDocument docs

June 26,  Structure

June 26,  Collaborations -- Creator relies on its subclasses to define the factory method so that it returns an instance of the appropriate ConcreteProduct

June 26, Prototype Object Creational Prototype Object Creational  Intent Specify the kinds of Objects to create using a prototypical instance,and create new objects by copying this prototype  Motivation You could build an editor for music scores by customizing a general framework for graphical editors and adding new objects that represent notes,rests, and staves. The editor framework may have a palette of tools for adding these music objects to the score. The palette would also include tools for selecting, moving, and otherwise manipulation music objects. Users will click on the quarter-note tool and use it to add quarter notes to the score. Or they can use the move tool to move a note up or down on the staff, thereby changing its pitch

June 26, Let’s assume the framework provides an abstract Graphics class for graphical components, like notes and staves. Moreover, it’ll provide an abstract Tool class for defining tools like those in the palette. The framework also predefines a GraphicTool subclass for tools that create instances of graphical objects and add them to the document

June 26,  structure

June 26,  Collaborations A client asks a prototype to clone itself

June 26, Command Object Behavioral Command Object Behavioral  Intent Encapsulate a request as an object,thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations  Motivation Sometimes it’s necessary to issue Sometimes it’s necessary to issue

June 26,  Structure

June 26,  Collaborations -- The clients creates a ConcreteCommand ojbect and specifies its reciever

June 26, Iterator Object Creational Iterator Object Creational  Intent Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation  Motivation List Count() Append(Element) Remove(Element) … ListIterator First() Next() IsDone() CurrentItem() index list

June 26,  Structure

June 26,  Collaborations -- A ConcreteIterator keeps track of the current object in the aggregate and can compute the succeeding object in the traversal

June 26, Mediator Mediator Object Behavioral  Intent Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.  What is a Mediator -- A mediator is responsible for controlling and coordinating the interactions of a group of objects. The mediator serves as an intermediary that keeps objects in the group form referring to each other explicitly. The objects only know the mediator, thereby reducing the number of interconnections

June 26,  Example aClient director aListBox director aFontDialogDirector aButton director anEntryField director

June 26,  Structure

June 26,  Collaborations Colleagues send and receive requests from a Mediator object. The mediator implements the cooperative behavior by routing requests between the appropriate colleague(s)

June 26, Observer Object Behavioral Observer Object Behavioral  Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically  Example A = 50% B= 30% C= 20% observers subject Change notification Requests, modifications Requests, modifications x y z a b c

June 26,  Structure

June 26,  Collaboration - ConcreteSubject notifies its observers whenever a change occurs that could make its observers’ state inconsistent with its own. - After being informed of a change in the concrete subject, a ConcreteObserver object may query the subject for information. ConcreteObserver uses this information to reconcile its state with that of the subject.

June 26, State Object Behavioral State Object Behavioral  Intent Allow an object to alter its behavior when its internal state changes. The Object will appear to change its class  Example State->Open TCPConnection Open() Close() Acknowledge() TcpState Open() Close() Acknowledge() TCPEstablishedTCPListenTCPClosed Open() Close() Acknowledge() Open() Close() Acknowledge() Open() Close() Acknowledge()

June 26,  Structure

June 26,  Collabortions - Context delegates state-specific requests to the current ConcreteState object. - Context is the primary interface for clients. Clients can configure a context with State objects. Once a context is configured, its clients don’t have to deal with the State objects directly. - Either Context or the ConcreteState subclasses can decide which state succeeds another and under what circumstances

June 26,  Intent Define a family of algorithms, encapsulate each one, and make them interchangeable.Strategy lets the algorithm vary independently from clients that use it  Example Compositor->compose() Composition Traverse() Repair() Compositor compose() Compose() compose() SimpleComposerArrayCompositor Strategy object Behavioral Strategy object Behavioral TexCompositor compose()

June 26,  Structure

June 26,  Collaborations - Strategy and Context interact to implement the chosen algorithm. A context may pass all data required by the algorithm to the strategy when the algorithm is called. Alternatively, the context can pass itself as an argument to Strategy operations. That lets the strategy call back on the context as required. - A context forwards requests from its clients to its strategy. Clients usually create and pass a ConcreteStrategy object to the context; thereafter, clients interact with the context exclusively. There is often a family of ConcreteStrategy classes for a client to choose from

June 26, Template Method Class Behavioral Template Method Class Behavioral  Intent Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.  Example Application AddDocument() openDocument() DoCreateDocument() canOpenDocument() AboutToOpenDocument MyApplication DoCreateDocument() canOpenDocument() AboutToOpenDocument Document Save() Open() Close() doRead() MyDocument DoRead() Return new MyDocument docs

June 26,  Structure

June 26,  Collaboration ConcreteClass relies on AbstractClass to implement the invariant steps of the algorithm

June 26, Visitor Object Behavioral Visitor Object Behavioral  Intent Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates  Example VariableRefNode AssignmentNode TypeCheck() GenerateCode() PrettyPrint() TypeCheck() GenerateCode() PrettyPrint() TypeCheck() GenerateCode() PrettyPrint() Node

June 26,  Structure

June 26,  Collaboration - A client that uses the Visitor pattern must create a ConcreteVisitor object and then traverse the object structure, visiting each element with the visitor - A client that uses the Visitor pattern must create a ConcreteVisitor object and then traverse the object structure, visiting each element with the visitor - When an element is visited, it calls the visitor operation that corresponds to its class. The element supplies itself as an argument to this operation to let the visitor access its state, if necessary. - When an element is visited, it calls the visitor operation that corresponds to its class. The element supplies itself as an argument to this operation to let the visitor access its state, if necessary.