Software Design Patterns

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Design Patterns based on book of Gang of Four (GoF) Erich Gamma, Richard Helm, Ralph Johnson, and John VlissidesGang of Four (GoF) Elements of Reusable.
1 Software Design Patterns Department of Computer Science Kent State University.
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.
CS590L - Lecture 6 1 CS590L Distributed Component Architecture References: - E. Gamma, R. Helm, R. Johnson, J. Vlissides, Design Patterns: Elements of.
Plab – Tirgul 12 Design Patterns
(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.
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini 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.
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
DESIGN PATTERNS Redesigning Applications And
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
(c) 2010 University of California, Irvine – André van der Hoek1June 29, 2015 – 08:55:05 Informatics 122 Software Design II Lecture 8 André van der Hoek.
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 Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
Design Patterns.
Design Patterns: Introduction. Creational Design Patterns General and reusable solutions to common problems in software design Software University
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.
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.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
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.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
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
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CSC 480 Software Engineering Design With Patterns.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
CS616: Software Engineering Spring 2009 Design Patterns Sami Taha.
Stephenson College DP 98 1 Design Patterns by Derek Peacock.
Design Patterns Introduction
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
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:
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
1 Good Object-Oriented Design Dr. Radu Marinescu Lecture 4 Introduction to Design Patterns.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Jim Fawcett CSE776 – Design Patterns Summer 2006
Design Patterns: MORE Examples
Design Patterns: Brief Examples
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
object oriented Principles of software design
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
CSC 480 Software Engineering
Design Patterns.
DESIGN PATTERNS : Introduction
Informatics 122 Software Design II
CSC 480 Software Engineering
Chapter 8, Design Patterns Introduction
CSE870: Advanced Software Engineering (Design Patterns): Cheng, Sp2002
Presented by Igor Ivković
Presentation transcript:

Software Design Patterns Muhammad Nasir m.nasir@iiu.edu.pk

Contents What is a Design Pattern? Elements of the Design Pattern What design patterns are NOT Describing Design Patterns Types of Design Patterns When to use Design Patterns Benefits of Design Patterns Draw backs to Design Patterns How to Select a Design Pattern

What is a Design Pattern? “Design Pattern is a solution to a recurring design problem”. “Design patterns represent solutions to problems that arise when developing software within a particular context”. A design pattern is not a finished design that can be transformed directly into code.

“ 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 in the same way twice ” Christopher Alexander, A Pattern Language, 1977 Context: City Planning and Building architectures

What is a Design Pattern? Patterns capture the static and dynamic structure and collaboration among key participants in software designs Especially good for resolving non-functional issues Patterns facilitate reuse of successful software architectures and designs.

What Makes it a Pattern? A Pattern must: Have a name and be referenced consistently Solve a problem and be useful Have a context and can describe where the solution can be used Recur in relevant situations Provide sufficient information to solve the problem

Elements of Design Patterns Design patterns have four essential elements: Pattern name Problem Solution Consequences

Pattern Name It represents: a design problem its solutions its consequences in a word or two Makes it possible for us to think of design solution at a higher level of abstraction “The Hardest part of programming is coming up with good variable [function, and type] names.”

Problem Explains the problem and its context Lists preconditions to apply the pattern

Solution Describes the elements that make up the Design Relationships Responsibilities Collaborations Abstract solution not concrete implementation i.e. UML Diagram

Consequences Results and trade-offs of applying the pattern Critical for: Evaluating design alternatives Understanding costs Understanding benefits of applying the pattern Includes the impacts of a pattern on a system’s: Flexibility Extensibility Portability

Design Patterns are NOT They are Not: Designs that can be encoded in classes and reused as (i.e., linked lists, hash tables) They are: “Descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.”

Design Pattern Descriptions Name and Classification: Essence of pattern Intent: What it does, its rationale, its context Also Known A: Other well-known names Motivation: Scenario illustrates a design problem Applicability: Situations where pattern can be applied Structure: Class and interaction diagrams Participants: Objects/classes and their responsibilities Collaborations: How participants collaborate Consequences: Trade-offs and results Implementation: Pitfalls, hints, techniques, etc. Sample Code Known Uses: Examples of pattern in real systems Related Patterns: Closely related patterns

Types of Patterns Creational patterns: Structural patterns: Deal with creating, initializing, and configuring classes and objects Structural patterns: Deal Composition of classes or objects Implementation of Interfaces, classes and objects. Behavioural patterns: Behavioural patterns characterize the ways in which classes or objects interact. How they distribute responsibility

Creational Patterns Abstract Factory: Builder: Factory Method: Provide an interface for building related or dependant objects without specifying their concrete class. Builder: Separate the construction of a complex object from its representation so that same construction process can create different representations. Factory Method: Define an interface for creating an object, but let subclass decide which class to instantiate. Factory Method lets a class defer instantiation to subclass.

Creational Patterns (cont.) Prototype: Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Singleton: Ensure a class only has one instance, and provide a global point of access to it.

Structural Patterns Adapter: Bridge: Composite: Decorator: Convert the interface of a class into another interface that clients expect. Adapter lets classes work together that couldn’t otherwise because of the incompatible interfaces. Bridge: Decouple an abstraction from its implementation so that the two can vary independently. Composite: Compose objects into tree structures to represent part-whole hierarchies. Composite lets client treat individual objects and compositions of objects uniformly. Decorator: Attach additional responsibilities to an object dynamically. Decorators provide a higher-level interface that makes the subsystem easier to use.

Structural Patterns (cont.) Facade: Simplifies the interface for a subsystem Flyweight: Many fine-grained objects shared efficiently. Proxy: Provide a placeholder for another object to control access to it.

Behavioural Patterns Chain of Responsibility: Command: Iterator: Request delegated to the responsible service provider Command: Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. Iterator: Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. Interpreter: Language interpreter for a small grammar Mediator: Coordinates interactions between its associates Memento: Snapshot captures and restores object states privately

Behavioral Patterns (cont.) Observer: Dependents update automatically when subject changes State: Object whose behaviour depends on its state Strategy: Abstraction for selecting one of many algorithms Template Method: Algorithm with some steps supplied by a derived class Visitor: 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.

Design Pattern Space Object Class Scope Behavioural Structural Chain of responsibility Command Iterator Mediator Memento Observer State Strategy Visitor Adapter (object) Bridge Composite Decorator Façade Flyweight Proxy Abstract factory Builder Prototype Singleton Object Interpreter Template method Adapter (class) Factory method Class Scope Behavioural Structural Creational Purpose The first categorization criterion, called purpose, reflects what a pattern does. Patterns can have either creational, structural, or behavioral purpose. Creational patterns concern the process of object creation. Structural patterns deal with the composition of classes or objects. Behavioral patterns characterize the ways in which classes or objects interact and distribute responsibility.

Categorization Terms Scope is the domain over which a pattern applies Class Scope: relationships between base classes and their subclasses (static semantics) Object Scope: relationships between peer objects Some patterns apply to both scopes. The second criterion, called scope, specifies whether the pattern applies primarily to classes or to objects. Class patterns deal with relationships between classes and their subclasses. These relationships are established through inheritance, so they are static—fixed at compile-time. Object patterns deal with object relationships, which can be changed at run-time and are more dynamic. Almost all patterns use inheritance to some extent. So the only patterns labeled "class patterns" are those that focus on class relationships. Note that most patterns are in the Object scope.

When to Use Patterns Solutions to problems that recur with variations No need for reuse if problem only arises in one context Solutions that require several steps: Patterns can be an overhead if solution is a simple linear set of instructions When you want a state of the art solution Patterns are useful for someone who really wants a smart solution.

Benefits of Design Patterns Promotes Reusability of design solutions Helps in Documentation Capture Expert knowledge and design tradeoffs Helps in Communication Helps in transition to OO Technology

Drawbacks to Design Patterns Patterns do not lead to direct code reuse Patterns are deceptively simple Teams may suffer from pattern overload Patterns are validated by experience and discussion rather than by automated testing Integrating patterns into a software development is a human-intensive activity.

How to Select a Design Pattern Consider how design pattern solve design problems. Scan Intent/Purpose sections. Study pattern’s similarities and contrasts.

References Gama, Helm, Johnson, Vlissides, Design Patterns Elements of Reusable Object-Oriented Software, Addison Wesley, 1995 B. Cheng – Michigan State University