Lecture 9 Design Patterns CSCI – 3350 Software Engineering II Fall 2014 Bill Pine.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

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.
18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
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.
(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.
Software Engineering I Object-Oriented Design Software Design Refinement Using Design Patterns Instructor: Dr. Hany H. Ammar Dept. of Computer Science.
DESIGN PATTERNS Redesigning Applications And
(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.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
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.
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.
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.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
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.
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.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
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.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
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.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Design Patterns: MORE Examples
Software Design Refinement Using Design Patterns
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
Design Patterns Introduction
Instructor: Dr. Hany H. Ammar
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
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:

Lecture 9 Design Patterns CSCI – 3350 Software Engineering II Fall 2014 Bill Pine

CSCI 3350Lecture Lecture Overview Background from architecture Basic design patterns Standard format Example patterns

CSCI 3350Lecture Background Recall the Chess Master Analogy The Software Design Master –Must know, understand, and apply the deisgn patterns There are hundreds of these patterns The more frequently occurring patterns have been cataloged We will examine a subset of these

CSCI 3350Lecture Introduction Motivation: Promote reuse at design level An o-o system is an assembly of classes Want to leverage previous efforts New systems contain functionality not present in old –Else why build a new one? Existing classes will likely be used in different ways than originally designed

CSCI 3350Lecture Introduction (continued) At least some of needed functionality will have been previously developed –Why re-invent the wheel? –Developing new implementations to familiar problems Is a waste of time and money while under development Serves as an injector of faults –And therefore a further waste of time and money Design patterns are an attempt to provide a body of knowledge to commonly recurring problems –In a standard format

CSCI 3350Lecture Introduction (continued) The standard reference for object-oriented design patterns is the book –Title: Design Patterns: Elements of Reusable Object-Oriented Software –Authors: Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides –The authors are referred to as the “Gang of Four” in object-oriented design literature

CSCI 3350Lecture Definition 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.”

CSCI 3350Lecture Definition (continued) What is the origin of design patterns? –Conventional architecture –Proposed by Christopher Alexander –The architectural patterns described towns and buildings A pattern is a bit of insight that conveys the essence of a proven solution to a commonly recurring problem

CSCI 3350Lecture Definition (continued) An analogy from Jim Coplien “I could tell you how to make a dress by specifying the route of a pair of scissors through a piece of cloth, in terms of angles and length of cut. Or, I could give you a pattern. By reading the specification, you would have no idea of what was being built. The pattern foreshadows the product; it is the rule for making the thing, but it is also, in many respects, the thing itself.”

CSCI 3350Lecture Basic Design Patterns GoF describes 23 of the more commonly recurring patterns The patterns are classified into three categories –Creational Concerned with creating object Object instantiation is deferred to a subclass –Structural Concerned with the composition of classes or objects –Behavioral How classes or object interact or distribute responsibility

CSCI 3350Lecture Design Pattern Classification Purpose CreationalStructuralBehavioral Class Scope Factory MethodAdapter(class)Interpreter Template Method Object Scope Abstract Factory Builder Prototype Singleton* Adapter* Bridge* Composite* Decorator Façade* Flyweight Proxy* Chain of Responsibility Command Iterator* Mediator Memento Observer* State Strategy Visitor

CSCI 3350Lecture Standard Format 13 section standard format –Pattern name and classification –Scope Class –Deals with relationships between classes and their subclasses –Established through inheritance and are static –Fixed at compile time Object –Deals with relationships between objects –Set or changed at runtime and are therefore dynamic

Standard Format (cont) –Category Creational Structural Behavioral CSCI 3350Lecture

CSCI 3350Lecture Standard Format (continued) –Intent What does the pattern do? What problem is solved? –Also known as (optional) Alternative names for the pattern –Motivation A scenario that illustrates –The problem –How the pattern solves the problem

CSCI 3350Lecture Standard Format (continued) –Applicability To what situation can the pattern be applied? A diagram of the classes involved –Uses OMT (Object Modeling Technique) not UML –Participants Classes or objects involved –Collaborations How the participants interact to carry out their responsibilities

CSCI 3350Lecture Standard Format (continued) –Consequences Trade-offs and results of using the pattern –Implementation Pitfalls, hints, and techniques Language-specific issues –Sample code Code snippets to illustrate the pattern –Known uses Examples of the pattern found in “real” systems

CSCI 3350Lecture Standard Format (continued) –Related Patterns Closely related patterns and differences among patterns When studying a design pattern, I find it helpful to begin with –Intent –Applicability –Known uses –Motivation

CSCI 3350Lecture Singleton (Object – Creational) Intent –To ensure that a class has only 1 instance –Provide a single point of access to the instance Applicability –Use the Singleton pattern when: There must be exactly 1 instance of a class That instance must be accessible to all from 1 point

CSCI 3350Lecture Singleton (continued) Known uses –Smalltalk only examples supplied by Gamma Motivation –To avoid conflicts, it is critical that some classes have only 1 instance A file system that is a class within an operating system

CSCI 3350Lecture Class Exercise Produce a list of classes that might be used to create a graph of the type shown –Your design should be highly modular Each aspect of the graph must be modeled as a separate class –The actual “drawing” will be achieved by calling a low level class Plot, whose specification is supplied

CSCI 3350Lecture Façade (Object-Structural) Intent –Provide a unified interface to a set of interfaces –Define a higher-level interface that make the underlying functionality easier to use Applicability –You need to provide a simple interface to a complex subsystem Many users don’t need the flexibility of the subsystem All that flexibility is difficult to manage Provide a default view of the subsystem

CSCI 3350Lecture Façade (continued) Known uses –Compilers Suppose you want to compile a single line Don’t need the hassle of calling the scanner, parser, parse tree generator, optimizer, code generator Provide a simple interface with defaults Motivation –Structure a system into a subsystem to manage complexity –Shield the client from complex interfaces

CSCI 3350Lecture Observer (Object-Behavioral) Intent –Define a one-to-many dependency between objects so all dependents of an object are notified when the primary object changes state Applicability –When an object’s state changes, with this change causing changes in other objects, but the changing object doesn’t know how many dependant objects there are

CSCI 3350Lecture Observer (continued) Known uses –Model / View / Controller Controller gets user inputs and sends message to model Model performs its calculations View displays the model’s state, when notified by subscribe/notify protocol Motivation –Create a loose coupling between the objects involved

CSCI 3350Lecture Proxy (Object-Structural) Intent –To provide a placeholder for another object Applicability –When you need a more versatile reference than a pointer –Client sends messages to the proxy –Proxy provides additional services Security Data validation –Can be used to delay server request until really needed

CSCI 3350Lecture Proxy (continued) Known uses –Instead of inserting a complex graphic into a document, insert a proxy –The proxy will load the real graphic when needed Motivation –When you need to enhance a server –Postpone an activity until it is needed

CSCI 3350Lecture Composite (Object-Structural) Intent –Decompose objects into tree structures that represent a part/whole hierarchy Applicability –When you need to represent whole/part relationship –When you want to treat objects and composition of objects equivalently

CSCI 3350Lecture Composite (continued) Known uses –File systems consist of Directories Files But directories can hold files and other directories –Composite drawings Motivation –Provide a uniform treatment of objects and composites of objects

CSCI 3350Lecture Adapter (Object-Structural) Intent –Convert the interface of a class into another interface more convenient for the client Applicability –When you want to use an existing class, but the interface doesn’t match the one you need –Need to use several classes, each with different interfaces

CSCI 3350Lecture Adapter (continued) Known uses –Suppose you have a Windows application that uses the Windows file system –You need to run the application under UNIX –Write an adapter that accepts Windows file system calls and in turn makes the appropriate UNIX file system calls Motivation –You have existing classes that provide the services you need, but not the interface

CSCI 3350Lecture Bridge (Object-Structural) Intent –Decouple an abstraction from its implementation to allow the two to vary independently Want to provide the capability to run an application on multiple platforms Applicability –When you want changes in the implementation to not affect their clients –When you want to hide the implementation from a client C++ (unfortunately) refers to this as a proxy class

CSCI 3350Lecture Bridge (continued) Known uses –Isolate graphic clients from the hardware –UNIX –Isolate clients using windowing from platform specifics Motivation –Isolate client abstractions from their implementation –Difference between Bridge and Adapter? The Adapter is used for existing client code The Bridge is an integral part of the initial design

CSCI 3350Lecture Iterator (Object-Behavioral) Intent –Provide a means of accessing the elements of an aggregate structure, sequentially, without exposing the underlying structure Applicability –To provide access without knowledge of the internals of the structure –To support multiple access to the object –To provide a means of traversal that is uniform across all aggregate structures

CSCI 3350Lecture Iterator (continued) Known uses –Java For each loop –Standard Template Library (C++) Iterator class Motivation –Isolate the structure from the means of traversing

CSCI 3350Lecture Summary This has been only a brief introduction to design patterns Recall directive from the opening analogy –These designs contain patterns that must be Understood Memorized Applied repeatedly At best you have only begun step 1