PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.

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

 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
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,
(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.
Design Patterns CS is not simply about programming
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
Chapter 8 Object Design Reuse and Patterns. Finding Objects The hardest problems in object-oriented system development are: –Identifying objects –Decomposing.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Introduction to software design patterns For CSE 3902 By: Matt Boggus.
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
Design Patterns Trends and Case Study John Hurst June 2005.
Design Patterns.
Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
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.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
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.
Y2 eProjects Session 4 – Advanced Topics. Objectives  Dynamic Models  Design Patterns (Optional)  Software testing (for S4) ACCP i7.1\Sem3_4\eProject\T4.
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
ECE450S – Software Engineering II
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
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.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
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.
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.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
object oriented Principles of software design
Presented by Igor Ivković
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Introduction to Design Patterns
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Presented by Igor Ivković
Presentation transcript:

PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns

2 Contents 7/16/2015 University of Kansas 2 Introduction to OO concepts Introduction to Design Patterns  What are Design Patterns?  Why use Design Patterns?  Elements of a Design Pattern  Design Patterns Classification  Pros/Cons of Design Patterns Popular Design Patterns Conclusion References

3 What are Design Patterns? What Are Design Patterns?  Wikipedia definition  “a design pattern is a general repeatable solution to a commonly occurring problem in software design”  Quote from Christopher Alexander  “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” (GoF,1995) 7/16/ University of Kansas

4 Why use Design Patterns? 7/16/2015 University of Kansas

5 Why use Design Patterns? Design Objectives  Good Design (the “ilities”)  High readability and maintainability  High extensibility  High scalability  High testability  High reusability 7/16/2015 University of Kansas

6 Why use Design Patterns? 7/16/2015 University of Kansas

7 Elements of a Design Pattern A pattern has four essential elements (GoF)  Name  Describes the pattern  Adds to common terminology for facilitating communication (i.e. not just sentence enhancers)  Problem  Describes when to apply the pattern  Answers - What is the pattern trying to solve? 7/16/2015 University of Kansas

8 Elements of a Design Pattern (cont.)  Solution  Describes elements, relationships, responsibilities, and collaborations which make up the design  Consequences  Results of applying the pattern  Benefits and Costs  Subjective depending on concrete scenarios 7/16/2015 University of Kansas

9 Design Patterns Classification A Pattern can be classified as Creational Structural Behavioral 7/16/2015 University of Kansas

10 Pros/Cons of Design Patterns Pros  Add consistency to designs by solving similar problems the same way, independent of language  Add clarity to design and design communication by enabling a common vocabulary  Improve time to solution by providing templates which serve as foundations for good design  Improve reuse through composition 7/16/2015 University of Kansas

11 Pros/Cons of Design Patterns Cons  Some patterns come with negative consequences (i.e. object proliferation, performance hits, additional layers)  Consequences are subjective depending on concrete scenarios  Patterns are subject to different interpretations, misinterpretations, and philosophies  Patterns can be overused and abused  Anti-Patterns 7/16/2015 University of Kansas

12 Popular Design Patterns Let’s take a look  Strategy  Observer  Singleton  Decorator  Proxy  Façade  Adapter 7/16/2015 University of Kansas

13 Strategy Definition Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. 7/16/2015 University of Kansas

Design Principles Identify the aspects of your application that vary and separate them from what stays the same Program to an interface, not an implementation Favor composition over inheritance 7/16/2015 University of Kansas 14

15 Strategy – Class diagram 7/16/2015 University of Kansas

16 Strategy - Problem 7/16/2015 University of Kansas

Strategy - Solution

18 Strategy Pros  Provides encapsulation  Hides implementation  Allows behavior change at runtime Cons  Results in complex, hard to understand code if overused 7/16/2015 University of Kansas

19 Observer Definition Defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. 7/16/2015 University of Kansas

Design Principles Identify the aspects of your application that vary and separate them from what stays the same Program to an interface, not an implementation Favor composition over inheritance Strive for loosely coupled designs between objects that interact 7/16/2015 University of Kansas 20

21 Observer – Class diagram 7/16/2015 University of Kansas

22 Observer - Problem 7/16/2015 University of Kansas

Observer - Solution

24 Observer Pros  Abstracts coupling between Subject and Observer  Supports broadcast communication  Supports unexpected updates  Enables reusability of subjects and observers independently of each other Cons  Exposes the Observer to the Subject (with push)  Exposes the Subject to the Observer (with pull) 7/16/2015 University of Kansas

25 Singleton Definition Ensure a class only has one instance and provide a global point of access to it. 7/16/2015 University of Kansas

26 Singleton – Class diagram 7/16/2015 University of Kansas

Singleton - Problem

Singleton - Solution

29 Singleton 7/16/2015 University of Kansas

30 Singleton Pros  Increases performance  Prevents memory wastage  Increases global data sharing Cons  Results in multithreading issues 7/16/2015 University of Kansas

31 Patterns & Definitions – Group 1 Strategy Observer Singleton Allows objects to be notified when state changes Ensures one and only one instance of an object is created Encapsulates inter-changeable behavior and uses delegation to decide which to use 7/16/2015 University of Kansas 31 7/16/2015 University of Kansas

32 Patterns & Definitions – Group 1 Strategy Observer Singleton Allows objects to be notified when state changes Ensures one and only one instance of an object is created Encapsulates inter-changeable behavior and uses delegation to decide which to use 7/16/2015 University of Kansas 32 7/16/2015 University of Kansas

33 Patterns & Definitions – Group 1 Strategy Observer Singleton Allows objects to be notified when state changes Ensures one and only one instance of an object is created Encapsulates inter-changeable behavior and uses delegation to decide which to use 7/16/2015 University of Kansas 33 7/16/2015 University of Kansas

34 Patterns & Definitions – Group 1 Strategy Observer Singleton Allows objects to be notified when state changes Ensures one and only one instance of an object is created Encapsulates inter-changeable behavior and uses delegation to decide which to use 7/16/2015 University of Kansas 34 7/16/2015 University of Kansas

35 Decorator Definition Attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to sub-classing for extending functionality. 7/16/2015 University of Kansas

Design Principles Identify the aspects of your application that vary and separate them from what stays the same Program to an interface, not an implementation Favor composition over inheritance Strive for loosely coupled designs between objects that interact Classes should be open for extension, but closed for modification 7/16/2015 University of Kansas 36

Decorator – Class diagram

38 Decorator - Problem 7/16/2015 University of Kansas

39 Decorator - Solution 7/16/2015 University of Kansas

40 Decorator Pros  Extends class functionality at runtime  Helps in building flexible systems  Works great if coded against the abstract component type Cons  Results in problems if there is code that relies on the concrete component’s type 7/16/2015 University of Kansas

41 Proxy Definition Provides a surrogate or placeholder for another object to control access to it 7/16/2015 University of Kansas

42 Proxy – Class diagram 7/16/2015 University of Kansas

43 Proxy - Problem 7/16/2015 University of Kansas

Proxy - Solution

45 Proxy Pros  Prevents memory wastage  Creates expensive objects on demand Cons  Adds complexity when trying to ensure freshness 7/16/2015 University of Kansas

46 Facade Definition Provides a unified interface to a set of interfaces in a subsystem. Façade defines a higher level interface that makes the subsystem easier to use. 7/16/2015 University of Kansas

Design Principles Identify the aspects of your application that vary and separate them from what stays the same Program to an interface, not an implementation Favor composition over inheritance Strive for loosely coupled designs between objects that interact Classes should be open for extension, but closed for modification Principle of least knowledge – talk only to your immediate friends 7/16/2015 University of Kansas 47

48 Façade – Class diagram 7/16/2015 University of Kansas

49 Façade - Problem 7/16/2015 University of Kansas

Façade - Solution

51 Facade Pros  Makes code easier to use and understand  Reduces dependencies on classes  Decouples a client from a complex system Cons  Results in more rework for improperly designed Façade class  Increases complexity and decreases runtime performance for large number of Façade classes 7/16/2015 University of Kansas

52 Adapter Definition Converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. 7/16/2015 University of Kansas

53 Adapter – Class diagram 7/16/2015 University of Kansas

54 Adapter - Problem 7/16/2015 University of Kansas

Adapter - Solution

56 Adapter Pros  Increases code reuse  Encapsulates the interface change  Handles legacy code Cons  Increases complexity for large number of changes 7/16/2015 University of Kansas

57 Patterns & Definitions – Group 2 Decorator Proxy Façade Adapter Simplifies the interface of a set of classes Wraps an object and provides an interface to it Wraps an object to provide new behavior Wraps an object to control access to it 7/16/2015 University of Kansas 57 7/16/2015 University of Kansas

58 Patterns & Definitions – Group 2 Decorator Proxy Façade Adapter Simplifies the interface of a set of classes Wraps an object and provides an interface to it Wraps an object to provide new behavior Wraps an object to control access to it 7/16/2015 University of Kansas 58 7/16/2015 University of Kansas

59 Patterns & Definitions – Group 2 Decorator Proxy Façade Adapter Simplifies the interface of a set of classes Wraps an object and provides an interface to it Wraps an object to provide new behavior Wraps an object to control access to it 7/16/2015 University of Kansas 59 7/16/2015 University of Kansas

60 Patterns & Definitions – Group 2 Decorator Proxy Façade Adapter Simplifies the interface of a set of classes Wraps an object and provides an interface to it Wraps an object to provide new behavior Wraps an object to control access to it 7/16/2015 University of Kansas 60 7/16/2015 University of Kansas

61 Patterns & Definitions – Group 2 Decorator Proxy Façade Adapter Simplifies the interface of a set of classes Wraps an object and provides an interface to it Wraps an object to provide new behavior Wraps an object to control access to it 7/16/2015 University of Kansas 61 7/16/2015 University of Kansas

62 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter 7/16/2015 University of Kansas 62 7/16/2015 University of Kansas

63 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter Behavioral 7/16/2015 University of Kansas 63 7/16/2015 University of Kansas

64 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter Behavioral 7/16/2015 University of Kansas 64 7/16/2015 University of Kansas

65 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter Behavioral Creational 7/16/2015 University of Kansas 65 7/16/2015 University of Kansas

66 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter Behavioral Creational Structural 7/16/2015 University of Kansas 66 7/16/2015 University of Kansas

67 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter Behavioral Creational Structural 7/16/2015 University of Kansas 67 7/16/2015 University of Kansas

68 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter Behavioral Creational Structural 7/16/2015 University of Kansas 68 7/16/2015 University of Kansas

69 Pattern Classification Strategy Observer Singleton Decorator Proxy Façade Adapter Behavioral Creational Structural 7/16/2015 University of Kansas 69 7/16/2015 University of Kansas

Conclusion - Design Principles Identify the aspects of your application that vary and separate them from what stays the same Program to an interface, not an implementation Favor composition over inheritance Strive for loosely coupled designs between objects that interact Classes should be open for extension, but closed for modification Principle of least knowledge – talk only to your immediate friends 7/16/2015 University of Kansas 70

71 Conclusion 7/16/2015 University of Kansas

72 References Design Patterns: Elements of Reusable Object-Oriented Software. Gamma, Helm, Johnson, and Vlissides (GoF). Addison-Wesley, Head First Design Patterns. Freeman and Freeman. O’REILLY, Design Patterns Explained. Shalloway and Trott. Addison-Wesley, Patterns of Enterprise Application Architecture. Fowler. Addison- Wesley, Core J2EE Pattern Catalog, Sun Developer Network, ject.html ject.html Object Oriented Software Construction. Meyer, Prentice Hall, /16/ University of Kansas

73 References Wikipedia, The Free Encyclopedia         7/16/2015 University of Kansas

Questions? 7/16/2015 University of Kansas 74

Thank You! 7/16/2015 University of Kansas 75