Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.

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

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
05/26/2004www.indyjug.net1 Indy Java User’s Group June Knowledge Services, Inc.
Design Patterns A brief introduction to what they are, why they are useful, and some examples of those that are commonly used.
(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
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
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Basic Design Patterns 1. Introduction Gabriel Mañana Ed. 453 Of. 120 Ext
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
CERN – European Organization for Nuclear Research GS Department – Administrative Information Services Design Patterns in Groovy Nicolas Décrevel Advanced.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Design Patterns Introduction. What is a Design Pattern?  A technique to repeat designer success.  Borrowed from Civil and Electrical Engineering domains.
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.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
GoF Sections Design Problems and Design Patterns.
DESIGN PATTERNS CSC532 Adv. Topics in Software Engineering Shirin A. Lakhani.
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.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
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.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
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.
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.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
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.
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Design Patterns Lecture 1
Introduction to Design Patterns
Behavioral Design Patterns
object oriented Principles of software design
9/21/2018 Sima Emadi.
DESIGN PATTERNS B.TECH IV YR II SEMESTER(TERM 08-09)
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
DESIGN PATTERNS : Introduction
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Presentation transcript:

Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm

What’s a pattern?  A pattern is a named abstraction from a concrete form that represents a recurring solution to a particular problem.

Categories of Patterns  Design patterns vary in granularity and level of abstraction.  By categorizing patterns, it becomes easier to recognize and learn them  patterns can be categorized by purpose or scope  purpose reflects what the pattern does  scope specifies if the pattern applies to classes or objects

purpose  reflects what the pattern does  Creational -- facilitate object creation  Structural -- deal with the composition of classes or objects  Behavioral -- deal with the way objects interact and distribute responsibility

scope  whether the pattern applies to classes or objects  class patterns: deal with relationships between classes or subclasses established through inheritance these relationships are fixed at compile time  objects patterns: deal with object relationships that can be changed at runtime

other ways to organize patterns  some patterns are frequently used with other patterns, for example composite is often used with visitor and/or iterator  some patterns are alternatives: Prototype is usually an alternative for Abstract Factory  Some patterns are very similar in structure, such as Composite and Decorator

How do Design Patterns Solve Design Problems?  The meaning of OO is well-known  The hard part is decomposing the system into objects to exploit: encapsulation flexibility, extensibility ease of modification performance evolution reusability

Finding objects  Many objects in the design come from the analysis model  But OO designs often end up with classes that have no counterpart in the real world  Design Patterns help the modeler to identify less obvious abstractions and the objects that can capture them.

Inheritance  Inheritance is a mechanism for reuse  you can define a new kind of object in terms of the old one  you get new implementations almost for free, inheriting most of what you need from an existing class  This is only half the story!

Program to an interface, not an implementation  Inheritance permits defining a family of objects with identical interfaces  polymorphism depends on this!  all derived classes share the base class interface  Subclasses add or override 0perations, rather than hiding operations  All subclasses then respond to requests in the interface of the abstract class

Inheritance properly used  clients are unaware of types of objects: heuristic “explicit case analysis on the type of an object is usually an error. The designer should use polymorphism”. Riel  clients only know about the abstract classes defining the interface. heuristic 5.7: “All base classes should be abstract”. Riel  This reduces implementation dependencies  program to an interface, not an implementation  creational patterns help ensure this rule!

Two techniques for reuse  inheritance: white box  object composition: black box

advantage of inheritance for reuse  defined statically  supported directly by the language: straightforward to use  easier to modify implementation being reused

disadvantage of inheritance  can’t change inherited implementation at run- time  parent classes often define part of their subclass’s physical representation  because inheritance exposes the parent implementation it’s said to “break encapsulation” (GOF p.19, Sny86)  change in parent => change in subclass  What if inherited attribute is inappropriate?

object composition: black box reuse  objects are accessed solely through their interfaces: no break of encapsulation  any object can be replaced by another at runtime: as long as they are the same type  favor object composition over class inheritance. GOF p. 20  but inheritance & composition work together!

Delegation  “a way of making composition as powerful for reuse as inheritance”: GOF, p. 20 [JZ91] Ralph Johnson and Jonathan Zweig, Delegation in C++, JOOP, f(11):22-35, Nov. 91 [Lie86] Henry Lieberman. Using prototypical objects to implement shared behavior in OO systems. OOPSLA, pp , Nov. ‘86

delegation: reuse  In delegation, 2 objects handle a request  analogous to subclass deferring request to parent  in delegation, the receiver passes itself to the delegate to let the delegated operation refer to the receiver!

delegating area() to rectangle Window area() Rectangle Has-a area() return rectangle->area() return width*height width height

advantages of delegation  can change behaviors at run-time  window can become square at run- time by replacing Rectangle with Square, (assuming Rectangle & Square are same type!)  There are run-time costs.  delegation in patterns: State, Strategy, Visitor, Mediator, Bridge

delegating area() to square Window area() Square Has-a area() return square->area() return side*side side

Patterns make design resistant to re-design Robustness to Change  Algorithmic dependencies: Template Method, Visitor, Iterator, Builder, Strategy.  Creating an object by specifying a class explicitly: Abstract Factory, Factory Method, Prototype  Dependence on specific operations: Command, Chain of Responsibility  Dependence on object representation or implementation: Abstract Factory, Bridge, Proxy  Tight coupling: Abstract Factory, Command, Facade, Mediator, Observer, Bridge

Patterns make design resistant to re- design  Extending functionality by subclassing: Command, Bridge, Composite, Decorator, Observer, Strategy  Inability to alter classes conveniently: Visitor, Adapter, Decorator

Design Confidence  Design Inexperience: “Is my design ok?”  Patterns engender confidence used twice & blame the GOF still room for creativity

Design Coverage  Large portion of design can be covered by patterns  Seductively simple to implement most explained in a few pages add no “extra-value” to end-user  You still have to write functionality: patterns don’t solve the problem

Design Understanding  Most people know the patterns If you’re looking at someone’s design & you identify a pattern, you immediately understand much of the design  Common design vocabulary “Let’s use a Builder here”  Design language beyond language syntax Problem-oriented language program in rather than into the language

Common Problems  Getting the “right” pattern  Taming over-enthusiasm you “win” if you use the most patterns everything solved by the last pattern you learned

How to select a pattern  know a basic catalog  scan intent section  study patterns of like purpose  consider a cause of redesign