Design Patterns.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

CS590L - Lecture 6 1 CS590L Distributed Component Architecture References: - E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of.
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
Design Patterns CS is not simply about programming
Copyright © Active Frameworks, Inc.. - All Rights Reserved - V2.0 Introduction - Page L1-1 PS95&96-MEF-L1-1 Dr. M.E. Fayad Creationa l Paradigm.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
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.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Powerpoint Templates Page 1 Powerpoint Templates What is Design Patterns ? by Indriati Teknik Informatika – UB.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Patterns and Reuse. Patterns Reuse of Analysis and Design.
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Chapter 8 Object Design Reuse and Patterns. Object Design Object design is the process of adding details to the requirements analysis and making implementation.
Design Patterns Introduction General and reusable solutions to common problems in software design SoftUni Team Software University
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Engineering 1. Analysis  Design 2 Characteristics of good design 3 The design must implement all of the explicit requirements contained in the.
Patterns in programming
Design Patterns-1 7 Hours.
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
Design Patterns: MORE Examples
The Object-Oriented Thought Process Chapter 15
Design Patterns (Chapter 6 of Text Book – Study just 8)
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
A Brief Introduction to Design Patterns
Pertemuan 08 Design Patterns & Anti-Patterns
Introduction to Design Patterns
Design Patterns Introduction
Behavioral Design Patterns
CIS 375 Bruce R. Maxim UM-Dearborn
Advanced Programming Behnam Hatami Fall 2017.
Introduction to Design Patterns Part 1
08/15/09 Design Patterns James Brucker.
Informatics 122 Software Design II
Patterns.
DESIGNING YOUR SYSTEM.
DESIGN PATTERNS : Introduction
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Introduction to Design Patterns
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Presented by Igor Ivković
Software Design Lecture : 27.
Presentation transcript:

Design Patterns

Motivation/Background (1) Developing software is hard Developing reusable software is even harder Why not leverage proven solutions to common problems? Two ways to do this: Design Patterns Support reuse of class-level design Capture static and dynamic structures and collaborations of successful solutions Frameworks Support reuse of detailed design and code Integrated set of components that provide partial solutions to problems

Motivation/Background (2) How do you become a software design master? Learn the foundations Algorithms, data structures, programming languages Learn the principles of good design Abstraction, encapsulation, and modularity Study the designs of masters Understand, memorize, mimic Practice Hands-on experience, multiple situations

Intro to Design Patterns Represent sound solutions to common problems that arise with particular contexts Particularly useful at resolving nonfunctional forces Ease of modification Ease of reuse Ease of extension A good design is revealed when you attempt to change it

An Example: The Observer Design Pattern (1) Sample application: stock quote service Intent: define one-to-many dependency between objects so that when one object changes state, all its dependent objects are notified

An Example: The Observer Design Pattern (2) Key Forces: There may be many observers Each observer may react differently to same notification The observable should be decoupled from the observers to allow them to change independently Observers should be able to query observable for required information

An Example: The Observer Design Pattern (3) Structure of the Design Pattern: Not really necessary

An Example: The Observer Design Pattern (4) Collaboration of the Design Pattern: Not needed

Canonical Design Pattern Description Name Intent Forces Non-Software Example Abstract Description Implementation Issues Consequences Java API Usage Responsibility-Driven Post-Mortem Example

Frameworks vs. Patterns (1) Important to understand the relationship between these two ways to reuse designs Frameworks (1) Semi-complete applications Can be tailored to specific applications Inheritance Template Instantiation Callbacks Frameworks provide domain-specific functionality Ex: Backtracking framework

Frameworks vs. Patterns (2) Frameworks exhibit inversion of control Framework acts on domain classes Framework pulls domain objects into process Typically through hooks or callbacks Benefits of Frameworks Enable direct reuse of code Enable reuse of overall design Drawbacks of Frameworks High initial learning curve Many classes, interfaces, levels of abstraction Flow of control is non-intuitive Pull versus push model Hard to see how domain code fits

Frameworks vs. Patterns (3) Several different types of software patterns Architectural Design Idioms Architectural Patterns Expose fundamental structural organization of system or subsystem Provide decomposition into subsystems Provide “big picture” of system High-level Abstraction Example: Blackboard Architecture

Frameworks vs. Patterns (4) Design Patterns Provide scheme for refining components Freeze commonly-reoccurring structure Middle-level Abstraction Example: Observer/Observable Notice how this could be used to implement a blackboard architecture Idioms Describe how to implement a particular aspect of a component in some language Low-level Abstraction Example: Reference Counts

Structure of Design Patterns (1) Divided by purpose and scope (1) Scope Does it apply to classes or objects? Class Patterns deal with relationships between classes Static – compile-time relationships Frequently involve inheritance Not the typical design pattern Object Patterns deal with relationships between objects Dynamic – change at run-time Frequently involve aggregation/delegation

Structure of Design Patterns (2) Divided by purpose and scope (2) Purpose What the pattern does Three categories Structural Patterns Creational Patterns Behavioral Patterns Deal with decoupling interface and implementation Set the system up for modification Examples: Adapter – translate one interface to another Composite – recursive aggregation

Structure of Design Patterns (3) Divided by purpose and scope (3) Creational Patterns Initialization and configuration Examples Singleton – controlled instance count Factory Method – use inheritance to create instances of abstract classes Behavioral Patterns Dynamic interactions among objects/classes Examples: Iterator – give sequential access to collection Template Method – separate variant and invariant aspects of process

Structure of Design Patterns (4) What makes a pattern a “pattern”? (1) Describe a problem A problem that arises frequently Explains forces at work Ex: Aspects that must be changed frequently Present a solution Proven solution to the problem Must indicate how it balances the active forces Must define both static and dynamic aspects of solution

Structure of Design Patterns (5) What makes a pattern a “pattern”? (2) Have a context Must indicate when/where the solution can be used Describes the situation in which the problem arises Recur Must be relevant to more than one situation Teach Must provide sufficient understanding to allow it to be tailored Name

Key Principles of Design Patterns Separate interface from implementation Program to the interface, not the implementation Separate variant from invariant aspects Define what is likely or desirable to change Build in flexibility for variant aspects Prefer aggregation/delegation/composition over inheritance Use aggregation to extend existing code Creates “black box” reuse Inheritance is for defining abstract hierarchies Open/Closed Principle Open to extension, closed to modification Easy to extend and does not require modification to do so

Key Benefits of Design Patterns Large-scale reuse of class architecture Above the single class level Capture expert knowledge/tradeoffs Improve developer communication Own vocabulary Encourage documentation/review

Design Pattern Books “Design Patterns”, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Excellent reference Not generally considered a good textbook Examples in C++ “Head First Design Patterns” by Eric Freeman and Elisabeth Freeman Better as a textbook Weaker as a reference Examples in Java Others…

Key Drawbacks of Design Patterns No direct code reuse Language-independent Must be recoded each time Deceptively simple Leads to misuse Overload Can be too many patterns to find what you want Validated only through experience/discussion No formal testing of design patterns Refactoring development process takes time Several attempts to understand how/when to use

Anti-Patterns Introduced by William Brown Tells what to avoid Classic book by same name Another good book - “Bitter Java”, by Bruce Tate Tells what to avoid Key is that it looks great but will fail An anti-pattern is A pattern that tells: how to go from a problem to a bad solution how to go from a bad solution to a good solution Simple Examples: Using primitive arrays rather than array objects Cut-and-paste programming – “one rule one place”