Chapter 6 Introduction to Design Patterns (Part I) COSC 4346: Software Engineering I Dr. Lappoon R. Tang.

Slides:



Advertisements
Similar presentations
Chapter 6 Introduction to Design Patterns. Sample Design Goals and Ways to Accomplish Them Reusability, Flexibility, and Efficiency o Reuse flexible designs.
Advertisements

Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
Copyright © Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy. All rights reserved. Basic Concepts Software Architecture Lecture 3.
Introduction To System Analysis and Design
July 11 th, 2005 Software Engineering with Reusable Components RiSE’s Seminars Sametinger’s book :: Chapters 16, 17 and 18 Fred Durão.
Fall 2007CS 225 Introduction to Software Design Chapter 1.
Unit 251 Implementation and Integration Implementation Unit Testing Integration Integration Approaches.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
CS350/550 Software Engineering Lecture 1. Class Work The main part of the class is a practical software engineering project, in teams of 3-5 people There.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
1 Working with Classes Chapter 6. 2 Class definition A class is a collection of data and routines that share a well-defined responsibility or provide.
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
Spring 2009CS 225 Introduction to Software Design Chapter 1.
Introduction to Software Design Chapter 1. Chapter 1: Introduction to Software Design2 Chapter Objectives To become familiar with the software challenge.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Design Patterns.
Chapter 10 Introduction to Components. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFramework Detailed.
Chapter 2 Object Orientation. Process Phase Affected by This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed Design.
Prologue: The Software Process. Main Phases of Software Process 1. Requirements Analysis (answers “WHAT?”) Specifying what the application must do 2.
Chapter 5 Design Principles II: Flexibility, Reusability, and Efficiency.
Lecture # 06 Design Principles II
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Chapter 5 Design Principles II: Flexibility, Reusability, and Efficiency.
Introduction By: Dr. Javad Razjouyan. Programming Languages.
Comp2110 Software Design lecture 13Detailed Design (1)  detailed design contrasted with high level design  introducing the Observer Design Pattern 
Invitation to Computer Science, Java Version, Second Edition.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Introduction to Software Design Chapter 1. Chapter Objectives  To become familiar with the software challenge and the software life cycle  To understand.
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
Software Design Patterns
SWE 316: Software Design and Architecture Objectives Lecture # 15 Behavioral Design Patterns SWE 316: Software Design and Architecture  To learn the behavioral.
Design engineering Vilnius The goal of design engineering is to produce a model that exhibits: firmness – a program should not have bugs that inhibit.
CS 350 – Software Design The Strategy Pattern – Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore.
Chapter 10 Analysis and Design Discipline. 2 Purpose The purpose is to translate the requirements into a specification that describes how to implement.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
SWE 316: Software Design and Architecture Objectives Lecture # 18 Introduction to Components SWE 316: Software Design and Architecture To learn:  benefits.
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 Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
Chapter 6 Introduction to Design Patterns. Process Phase Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed.
Chapter 1 Programming Review and Introduction to Software Design.
Chapter 4 Design Principles I Correctness and Robustness.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 13 Creational Design Pattern SWE 316: Software Design and Architecture.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Software Engineering Modern Approaches Eric Braude and Michael Bernstein 1.
1 OO Analysis & Design - Introduction to main ideas in OO Analysis & design - Practical experience in applying ideas.
Introduction to Software Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
© 2010 John Wiley & Sons Ltd. Software Engineering Modern Approaches Eric Braude and Michael Bernstein 1.
Software Design Patterns 1 Gang of Four (GoF, made up of Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.
ANU comp2110 Software Design lecture 8 COMP2110 Software Design in 2004 lecture 8 Software Architecture 1 of 2 (design, lecture 3 of 6) Goal of this small.
Review of Parnas’ Criteria for Decomposing Systems into Modules Zheng Wang, Yuan Zhang Michigan State University 04/19/2002.
Quality Assurance in the Presence of Variability Kim Lauenroth, Andreas Metzger, Klaus Pohl Institute for Computer Science and Business Information Systems.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Chapter 7 Creational Design Pattern. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed.
February 19, February 19, 2016February 19, 2016February 19, 2016 Azusa, CA Sheldon X. Liang Ph. D. Software Engineering in CS at APU Azusa Pacific.
CSIS 4850: CS Senior Project – Spring 2009 CSIS 4850: Senior Project Spring 2009 Object-Oriented Design.
Slide 1 Systems Analysis and Design with UML Version 2.0, Second Edition Alan Dennis, Barbara Wixom, and David Tegarden Chapter 9: Moving on to Design.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Evolution, Architecture, and Metamorphosis By: Brian Foote and Joseph Yoder University of Illinois Presented by: Gleyner Garden.
1 M206 Chapter 31: An Overview of Software Development 1.Defining the problem 2.Analyzing the requirement – constructing initial structural model 3.Analyzing.
Object-Oriented Software Engineering Using UML, Patterns, and Java,
CS 350 – Software Design The Strategy Pattern – Chapter 9
OOP What is problem? Solution? OOP
Software Design Patterns
Object-Oriented Design
Software Reuse Objectives
Chapter 5 Designing the Architecture Shari L. Pfleeger Joanne M. Atlee
CSSSPEC6 SOFTWARE DEVELOPMENT WITH QUALITY ASSURANCE
Software Design Patterns
C++ Object Oriented 1.
Presentation transcript:

Chapter 6 Introduction to Design Patterns (Part I) COSC 4346: Software Engineering I Dr. Lappoon R. Tang

Overview o Recurring Design Purposes o What are Design Patterns? o The abstract factory pattern

Readings o Section 6.1 o Section 6.2

Review: Sample Design Goals and Ways to Accomplish Them Reusability, Flexibility, and Maintainability oReuse flexible designs oKeep code at a general level oMinimize dependency on other classes Robustness oReuse reliable designs oReuse robust parts Sufficiency / Correctness oModularize design oReuse trusted parts Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Case study: KitchenViewer o Suppose we want to create an application KitchenViewer that can display a design for our kitchen oWall cabinet oCounter oFloor cabinet o The application can also render a style for the kitchen oModern oClassic oAntique oArts & Crafts

KitchenViewer Interface Wall cabinet Counter Floor cabinet ModernClassicAntiqueArts & Crafts menu display area styles Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

KitchenViewer Example ModernClassicAntiqueArts & Crafts Wall cabinets Floor cabinets Countertop Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Selecting Antique Style ModernClassicAntiqueArts & Crafts Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Design Goals vs. Design Purposes o A design goal (such as reusability) is generally too high level o When confronted with an actual design problem, one needs to translate a goal into specific design purpose oExample: A goal is to reuse a part of a calendar application, it may be translated into a specific design purpose to parameterize a set of methods so that they can be applied to any day, month, year

Design Purpose: KitchenViewer o Suppose our design goal here is flexibility o To achieve the goal, what should be our design purpose? oExample: the procedure for rendering various styles is basically the same, there should be no need for more than one copy of this procedure renderKitchen() o More precisely, the design purpose can be stated as follows: oAn application must construct a family of objects at runtime: The design must enable choice among several styles

What are Design Patterns? o Class combinations and accompanying algorithms that fulfill common design purposes o A design pattern expresses an idea rather than a fixed class combination oAccompanying algorithms express the patterns basic operation

What are Design Patterns? o Design patterns express an idea instead of specific details oExample: In house building, the term ranch style denotes a useful house pattern; it is an idea only, the specific details in building the house according to ranch style has yet to be worked out

Bad example first: without design patterns // Sample code for renderKitchen() – version ignoring design purpose // Determine the style... // Case statement // Assume that the antique style was selected. // Create the antique wall cabinets AntiqueWallCabinet antiqueWallCabinet1 = new AntiqueWallCabinet(); AntiqueWallCabinet antiqueWallCabinet2 = new AntiqueWallCabinet();... // Create the antique floor cabinets AntiqueFloorCabinet... // Create the kitchen object, assuming the existence of add() method Kitchen antiqueKitchen = new Kitchen(); antiqueKitchen.add(antiqueWallCabinet1,...); // rest of parameters specify location antiqueKitchen.add(antiqueWallCabinet2,...); // Add antique floor cabinets to the kitchen... // Render antiqueKitchen...

Bad example first: without design patterns renderKitchen() uses the classes Kitchen, WallCabinet, FloorCabinet oThis method is placed in a class called Client (conceptually the application class or a class to be used by the application class) o As you can see, the code is going to be repetitive, inflexible, and hardly reusable oOne copy of such code is needed for every type of style (e.g. modern)

KitchenViewer Without Design Patterns Kitchen Client renderKitchen() FloorCabinet ModernWallCabinet ModernFloorCabinetAntiqueFloorCabinet AntiqueWallCabinet WallCabinet Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Design Goal At Work: Flexibility Our design should be flexible enough to produce any of the several kitchen styles. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

How do we deal with the problem? Problem: … new AntiqueWallCabinet(); o Applies only to antique style because objects of the class AntiqueWallCabinet can only access methods related to rendering antique wall cabinets Solution: o … myStyle.getWallCabinet(); The class of the object myStyle will check at runtime which style (e.g. antique or modern?) is being rendered and then the corresponding method for rendering is used.

AntiqueKStyle getWallCabinet() getFloorCabinet() The Abstract Factory Idea KitchenStyle getWallCabinet() getFloorCabinet() ModernKStyle getWallCabinet() getFloorCabinet() WallCabinetFloorCabinet AntiqueWallCabinetAntiqueFloorCabinet FloorCabinet getFloorCabinet() { return new AntiqueFloorCabinet(); } …… FloorCabinet getFloorCabinet() { return new ModernFloorCabinet(); } Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Abstract Factory Design Pattern Applied to KitchenViewer KitchenStyle getWallCabinet() getFloorCabinet() Kitchen getWallCabinet() getFloorcabinet() Client renderKitchen( KitchenStyle ) ModernKStyle getWallCabinet() getFloorCabinet() AntiqueKStyle getWallCabinet() getFloorCabinet() WallCabinetFloorCabinet ModernWallCabinet ModernFloorCabinet AntiqueWallCabinet AntiqueFloorCabinet Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Abstract Factory Design Pattern Applied to KitchenViewer // renderKitchen(KitchenStyle* myStyle) – using design pattern // Note: Code is adapted for C++. // Create wall cabinets, type decided by the class of myStyle WallCabinet* wallCabinet1 = myStyle -> getWallCabinet(); WallCabinet* wallCabinet2 = myStyle -> getWallCabinet();... // Create floor cabinets FloorCabinet* floorCabinet1 = myStyle -> getFloorCabinet(); FloorCabinet* floorCabinet2 = myStyle -> getFloorCabinet();... Kitchen kitchen = new Kitchen(); kitchen.add(wallCabinet1,...); kitchen.add(wallCabinet2,...);... // Add floor cabinet to kitchen

Abstract Factory Design Pattern Style getComponentA() getComponentB() Client doOperation( Style myStyle ) Style1 getComponentA() getComponentB() Style2 getComponentA() getComponentB() ComponentAComponentB Style1ComponentA Style1ComponentB Style2ComponentA Style2ComponentB Collection Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Abstract Factory Design Pattern Alternative Style getComponentA() getComponentB() Client doOperation() Style1 getComponentA() getComponentB() Style2 getComponentA() getComponentB() ComponentAComponentB Style1ComponentA Style1ComponentB Style2ComponentA Style2ComponentB Collection getComponentA() getComponentB() Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept: Design Pattern -- Definition: class combination and algorithms that fulfill a common design purpose. The abstract factory pattern: * Achieves design purposes derived from the design quality flexibility * Key ideas: o Parameterize the methods that are supposed to be flexible and easily extendable o Make the class containing the flexible methods depend on or aggregate an abstract class to which new sub-classes (thus new functionalities) can be added. o Make the sub-classes of the abstract class in turn depend on sub-classes of other abstract classes needed by the design Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.