Design Patterns.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Creational Design Patterns. Creational DP: Abstracts the instantiation process Helps make a system independent of how objects are created, composed, represented.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
CSE3308/CSC Software Engineering: Analysis and DesignLecture 5B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/CSC3080/DMS/2000/12.
Plab – Tirgul 12 Design Patterns
CSE Software Engineering: Analysis and Design, 2005Lecture 8A.1 Software Engineering: Analysis and Design - CSE3308 Design and Analysis Patterns.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
Nov, 1, Design Patterns PROBLEM CONTEXT SOLUTION A design pattern documents a proven solution to a recurring problem in a specific context and its.
CSE Software Engineering: Analysis and Design, 2002Lecture 7B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/DMS/2002/15.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Creational Patterns (1) CS350, SE310, Fall, 2010.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
02 - Creational Design Patterns Moshe Fresko Bar-Ilan University תשס"ח 2008.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
ECE450S – Software Engineering II
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 13 Creational Design Pattern SWE 316: Software Design and Architecture.
DESIGN PATTERNS Sanjeeb Kumar Nanda 30-Aug What is a pattern? Pattern is a recurring solution to a standard problem Each Pattern describes a problem.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Design Patterns Introduction
Advanced Object-oriented Design Patterns Creational Design Patterns.
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.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
S.Ducasse Stéphane Ducasse 1 Decorator.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
The Abstract Factory Pattern (Creational) ©SoftMoore ConsultingSlide 1.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
S.Ducasse Stéphane Ducasse 1 Adapter.
S.Ducasse Stéphane Ducasse 1 Abstract Factory.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Abstract Factory Pattern Jiaxin Wang CSPP Winter 2010.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
Abstract Factory Pattern
Design Patterns: Brief Examples
Software Design Patterns
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Introduction to Design Patterns
Design Patterns with C# (and Food!)
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Presented by Igor Ivković
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
Decorator Pattern Intent
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
CSC 480 Software Engineering
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Creational Patterns.
Informatics 122 Software Design II
CSC 480 Software Engineering
Presented by Igor Ivković
Decorator Pattern.
Presentation transcript:

Design Patterns

Design Patterns Design patterns are solutions to problems that arise when developing software within a particular context Patterns capture the structure and collaboration among key participants in software designs Patterns facilitate reuse of successful software architectures and designs

Design Pattern Descriptions Name Problem What is the problem and the context where we would use this pattern? Under what specific conditions should this pattern be used? Solution A description of the elements that make up the design pattern Emphasizes their relationships, responsibilities, and collaborations Not a concrete design or implementation; rather an abstract description Positive and negative consequences of use The pros and cons of using the pattern Includes impacts on reusability, portability, and extensibility

Organizing Patterns Purpose: What a pattern does Creational: creating, initializing and configuring classes and objects Structural patterns: composition of classes and objects Behavioral patterns: dynamic interactions among classes and objects Scope: what the pattern applies to Class patterns: Focus on the relationships between classes and their subclasses Involve inheritance reuse Object patterns: Focus on relationships between objects Involve composition reuse

Patterns and Language Most design patterns focus on OO Assume inheritance, polymorphism, encapsulation, etc. In procedural languages, might add OO features as “patterns” Some languages provide or make it easier to implement some patterns

Abstract Factory Provide an interface for creating families of related or dependent objects without specifying their concrete classes

Abstract Factory

Abstract Factory Use the Abstract Factory pattern when a system should be independent of how its products are created, composed, and represented. a system should be configured with one of multiple families of products. a family of related product objects is designed to be used together, and you need to enforce this constraint. you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations.

Abstract Factory AbstractFactory (WidgetFactory) declares an interface for operations that create abstract product objects. ConcreteFactory (MacintoshWidgetFactory, LinuxWidgetFactory) implements the operations to create concrete product objects. AbstractProduct (Window, ScrollBar) declares an interface for a type of product object. ConcreteProduct (MacintoshWindow, MacintoshScrollBar) defines a product object to be created by the corresponding concrete factory. implements the AbstractProduct interface. Client uses only interfaces declared by AbstractFactory and AbstractProduct classes.

Abstract Factory 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. AbstractFactory defers creation of product objects to its ConcreteFactory subclass.

Abstract Factory Consequences It isolates concrete classes It makes exchanging product families easy It promotes consistency among products Supporting new kinds of products is difficult

Factory Method Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

Factory Method

Factory Method Use the Factory Method pattern when a class can't anticipate the class of objects it must create. a class wants its subclasses to specify the objects it creates.

Factory Method Participants Product (Document) defines the interface of objects the factory method creates. ConcreteProduct (MyDocument) implements the Product interface. Creator (Application) declares the factory method, which returns an object of type Product. Creator may also define a default implementation of the factory method that returns a default ConcreteProduct object. may call the factory method to create a Product object. ConcreteCreator (MyApplication) overrides the factory method to return an instance of a ConcreteProduct.

Singleton Ensure a class only has one instance, and provide a global point of access to it.

Singleton Use the Singleton pattern when there must be exactly one instance of a class, and it must be accessible to clients from a well-known access point. when the sole instance should be extensible by subclassing, and clients should be able to use an extended instance without modifying their code.

Singleton Consequences Controlled access to sole instance Permits refinement of operations Permits a variable number of instances More flexible than class operations

Adapter Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Adapter

Adapter

Adapter

Decorator Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Decorator

Decorator Use Decorator to add responsibilities to individual objects dynamically and transparently, that is, without affecting other objects. for responsibilities that can be withdrawn. when extension by subclassing is impractical.

Decorator Participants Component (VisualComponent) defines the interface for objects that can have responsibilities added to them dynamically. ConcreteComponent (TextView) defines an object to which additional responsibilities can be attached. Decorator maintains a reference to a Component object and defines an interface that conforms to Component's interface. ConcreteDecorator (BorderDecorator, ScrollDecorator) adds responsibilities to the component.

Decorator Consequences More flexibility than static inheritance Avoids feature-laden classes high up in the hierarchy A decorator and its component aren't identical Lots of little objects

Facade Toolkit vs. application A facade is a class with a level of functionality that lies between a toolkit and a complete application The intent of the facade pattern is to provide an interface that makes a subsystem easy to use

Observer

Observer Use the Observer pattern in any of the following situations: When a change to one object requires changing others, and you don't know how many objects need to be changed. When an object should be able to notify other objects without making assumptions about who these objects are. In other words, you don't want these objects tightly coupled.

Observer Participants Subject Observer ConcreteSubject knows its observers. Any number of Observer objects may observe a subject. provides an interface for attaching and detaching Observer objects. Observer defines an updating interface for objects that should be notified of changes in a subject. ConcreteSubject stores state of interest to ConcreteObserver objects. sends a notification to its observers when its state changes. ConcreteObserver maintains a reference to a ConcreteSubject object. stores state that should stay consistent with the subject's. implements the Observer updating interface to keep its state consistent with the subject's.