Design Patterns Outline

Slides:



Advertisements
Similar presentations
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Advertisements

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.
1 CS 501 Spring 2005 CS 501: Software Engineering Lecture 17 Object Oriented Design 3.
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,
CSE Software Engineering: Analysis and Design, 2002Lecture 7B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/DMS/2002/15.
Design Patterns CS is not simply about programming
1 CS 501 Spring 2008 CS 501: Software Engineering Lectures 17 & 18 Object Oriented Design 3 & 4.
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
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.
1 CS 501 Spring 2007 CS 501: Software Engineering Lectures 17 & 18 Object Oriented Design 3 & 4.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
© SERG Software Design (OOD Patterns) Object-Oriented Design Patterns Topics in Object-Oriented Design Patterns Compliments of Spiros Mancoridis Material.
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.
Introduction to the Unified Modeling Language “The act of drawing a diagram does not constitute analysis or design. … Still, having a well-defined and.
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.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
CSC 480 Software Engineering Design With Patterns.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Design Patterns Introduction
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.
SOLID Design Principles
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Design Patterns A brief introduction to what they are, why they are useful, and some examples of those that are commonly used.
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Object-Oriented Modeling with UML
Pertemuan 08 Design Patterns & Anti-Patterns
Design Patterns Introduction
Behavioral Design Patterns
Observer Design Pattern
object oriented Principles of software design
Presented by Igor Ivković
Object-Oriented Design Patterns
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
Web Programming Language
Object Oriented Design Patterns - Structural Patterns
Patterns.
CSC 480 Software Engineering
Observer Pattern 1.
Software Design Lecture : 14.
DESIGN PATTERNS : Introduction
Introduction to Design Patterns
Advanced ProgramMING Practices
Introduction to Design Patterns
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Advanced ProgramMING Practices
Informatics 122 Software Design II
CSC 480 Software Engineering
Presented by Igor Ivković
Presentation transcript:

Design Patterns Outline  What is a Design Pattern One Example: Proxy (structural) Some Object-oriented Design Principles Some Examples: Adapter (structural) Observer (behavioral) Abstract Factory (creational) 1

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” [2] And they are meant for idea reuse, design reuse and also code reuse Design patterns help to write good programs. 2

A Pioneer Book on Design Patterns: Design Patterns elements of Reusable Object-Oriented Software[2] The book explains what is meant by a design pattern and 23 patterns are presented in catalog form 3

What is a Design Pattern? A design pattern is extracted/abstracted from existing software solutions; they represent abstract knowledge about how to solve a design problem. Design patterns are object-oriented and typically presented in UML 4

Anti-Patterns – a Design to Avoid From Wikipedia In computer science, anti-patterns are specific repeated practices that appear initially to be beneficial, but ultimately result in bad consequences that outweigh the hoped-for advantages. Languages have built-in patterns, e.g. handling of list in Lisp – also called idiom-patterns! 5

According to [2] a Pattern has Four Essential Elements: 1. Pattern name. 2. The problem describes when to apply the pattern. 3. The solution describes the elements (typically classes and objects) that makes up the design, their relationships, responsibilities, and collaborations. 4. The consequences are the results and tradeoffs of applying the pattern (time, space, language, flexibility, portability). 6

Classifying the Design Patterns after Purpose Creational: Describe how objects are created and configured. Structural: Describe composition of objects. Behavioral: Describes the way objects interact and distribute responsibility. 7

Design Patterns Outline What is a Design Pattern One Example: Proxy (structural) Some Object-oriented Design Principles Some Examples: Adapter (structural) Observer (behavioral) Abstract Factory (creational)  8

Proxy (structural) [2] Purpose: Provide a surrogate or placeholder for another object to control access to it. 9

<<interface>> Subject The Proxy Pattern <<interface>> Subject request() Client refersTo RealSubject Proxy request() request() refersTo-> request() 10

Proxy Pattern - Interaction Diagram :Client :Proxy :RealSubject request() request() 11

Design Patterns Outline What is a Design Pattern One Example: Proxy (structural) Some Object-oriented Design Principles Some Examples: Adapter (structural) Observer (behavioral) Abstract Factory (creational)  12

Some Object-Oriented Design Principles Keep the accessibility to classes and objects low. E.g. by: Using a high level of abstraction so that implementation details are hidden. Using encapsulation (e.g. getters / setters). Reference to interfaces and not to implementation classes. Abstraction as opposed to referencing implementation details! Program to an interface – allows change of implementation.

Open/Closed Principle From Wikipedia Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification; that is, such an entity can allow its behaviour to be modified without altering its source code. Two ways to realize this: That class could reuse coding from the original class through inheritance. The use of abstracted interfaces, where the implementations can be changed and multiple implementations could be created. This is especially valuable in a production environment, where changes to source code may necessitate code reviews, unit tests, and other such procedures to qualify it for use in a product: Code obeying the principle doesn't change when it is extended, and therefore needs no such effort.

Liskov Substitution Principle From Wikipedia In object-oriented programming, the Liskov substitution principle is a particular definition of subtype that was introduced by Barbara Liskov and Jeannette Wing in a 1993 paper entitled Family Values: A Behavioral Notion of Subtyping. The principle was formulated succinctly as follows: Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T. Thus, Liskov and Wing's notion of "subtype" is based on the notion of substitutability; that is, if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program (e.g., correctness).

Design Patterns Outline What is a Design Pattern One Example: Proxy (structural) Some Object-oriented Design Principles Some Examples: Adapter (structural) Observer (behavioral) Abstract Factory (creational)  16

Adapter (structural) Adapter pattern – From Wikipedia, the free encyclopedia Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Example: Temperature reading from different sensors.

Design Patterns Outline What is a Design Pattern One Example: Proxy (structural) Some Object-oriented Design Principles Some Examples: Adapter (structural) Observer (behavioral) Abstract Factory (creational)  18

Observer Pattern (behavioral) Defines a one-to-many dependency between objects so that when one object changes state, all it dependents are notified and updated automatically. This resembles the event source and listener structure of Java Beans. 19

Observer Pattern Model observers Subject Observer update() * attach(Observer) detach(Observer) notify() for all o in observers{ o.update(); } subject ConcreteSubject ConcreteObserver Invariant: observeState = subjectState subjectState observerState getSubjectState() setSubjectState() update() return subjectState observeState = subject.getState() 20

Subject-Observer

Listener Pattern in Java beans Button addActionListener(ActionListener) removeActionListener(ActionListener) processActionEvent(ActionEvent e) actionListener * <<interface>> ActionListener actionPerformed(ActionEvent) ConcreteListener actionPerformed(ActionEvent) for all l in actionlistener{ l. actionPerformed(e); } MyButton Typically not necessary. Button class used directly ActionEvent getActionCommand() Returns the command name associated with this action. Drop! 22

Design Patterns Outline What is a Design Pattern One Example: Proxy (structural) Some Object-oriented Design Principles Some Examples: Adapter (structural) Observer (behavioral) Abstract Factory (creational)  23

Abstract Factory (Creational) [2] Provides an interface for creating families of related or dependent objects without specifying their concrete classes. Example: An application supporting multiple look-and-feel standards like Windows and Motif. Most of the code should be without knowledge of which look-and-feel that is used.

Abstract Factory: Example WidgetFactory createScrollBar() createWindow() Client ScrollBar WindowsScrollBar MotifScrollBar MotifFactory createScrollBar() createWindow() WindowsFactory WidgetFactory is abstract, so either MotifFactory or WindowsFactory is instantiated “instantiate” Window WindowsWindow MotifWindow

Abstract Factory: Object Diagram … WidgetFactory factory = new MotifFactory(); ... ScrollBar sb = factory.createScrollBar(); … Window win = factory.createWindow() Motif look-and-feel is selected; CreateScrollBar and CreateWindow are called. factory:MotifFactory :Client sb:MotifScrollBar win:MotifWindow

Abstract Factory: a General Class Diagram Client AbstractProductA createProductA() createProductB() “instantiate” ProductA2 ProductA1 ConcreteFactory1 ConcreteFactory2 AbstractProductB createProductA() createProductB() createProductA() createProductB() “instantiate” ProductB2 ProductB1 “instantiate” “instantiate”

Abstract factory pattern - From Wikipedia, the free encyclopedia Use of interfaces

Abstract factory pattern - From Wikipedia, the free encyclopedia Use of interfaces

References [1] Christopher Alexander et al.: A Pattern Language Oxford University Press, New York, 1977 [2] Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides: Design Patterns Elements of Reusable Object-oriented Software Addison-Wesley, 1995 [3] Grady Booch, James Rumbaugh, Ivar Jacobson: The Unified Modeling Language User Guide Addison-Wesley, 1999 [4] Clemens Szyperski: Component Software Beyond Object-Oriented Programming Addison-Wesley, 1999 30