Chapter 6 Introduction to Design Patterns. Process Phase Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Chapter 6 Introduction to Design Patterns. Sample Design Goals and Ways to Accomplish Them Reusability, Flexibility, and Efficiency o Reuse flexible designs.
Chapter 6 Introduction to Design Patterns (Part I) COSC 4346: Software Engineering I Dr. Lappoon R. Tang.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Figures – Chapter 7.
Chapter 7 – Object-Oriented Design
COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Chapter 1 The Systems Development Environment
1 Objectives To introduces the concept of software Design. To introduce the concept of Object- Oriented Design (OOD). To Define various aspects about object.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
Chapter 4 Design Principles I Correctness and Robustness
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture # 05: Design Principles I - Correctness and Robustness SWE 316: Software.
Design Patterns.
Chapter 10 Introduction to Components. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFramework Detailed.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Chapter 2 Object Orientation. Process Phase Affected by This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed Design.
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.
Comp2110 Software Design lecture 13Detailed Design (1)  detailed design contrasted with high level design  introducing the Observer Design Pattern 
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 7 Requirements and Domain Classes SWE 316: Software Design and Architecture.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Abstract Factory Design Pattern making abstract things.
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.
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
1 COMP 350: Object Oriented Analysis and Design Lecture 1Introduction References: Craig Larman Chapter 1.
SWE 316: Software Design and Architecture Objectives Lecture # 18 Introduction to Components SWE 316: Software Design and Architecture To learn:  benefits.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Design Principle & Patterns by A.Surasit Samaisut Copyrights : All Rights Reserved.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Chapter 4 Design Principles I Correctness and Robustness.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 13 Creational Design Pattern SWE 316: Software Design and Architecture.
CSC 480 Software Engineering Design With Patterns.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
Chapter 8 Structural Design Patterns
Software Engineering Modern Approaches Eric Braude and Michael Bernstein 1.
Using Software Design Patterns Bill Anderson. About me Fox developer since 1987 Fox developer since 1987 Program Director, Los Angeles Visual Foxpro Developers.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 31. Review Creational Design Patterns – Singleton Pattern – Builder Pattern.
Software Design Patterns 1 Gang of Four (GoF, made up of Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
Slide 1 Systems Analysis and Design With UML 2.0 An Object-Oriented Approach, Second Edition Chapter 2: Introduction to Object-Oriented Systems Analysis.
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.
Chapter 7 Creational Design Pattern. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Computer System Structures
Design Patterns: MORE Examples
COMP2110 Software Design in lecture 14 Patterns(1) /Detailed Design
Chapter 5 – Design and Implementation
Chapter 7 – Object-Oriented Design
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Introduction to Design Patterns
Data Abstraction: The Walls
Design Patterns.
Design Patterns with C# (and Food!)
Software Design Patterns
Chapter 9 Behavioral Design Patterns
Software Design Patterns
An Introduction to Software Architecture
Chapter 8, Design Patterns Introduction
Agenda Software development (SD) & Software development methodologies (SDM) Orthogonal views of the software OOSD Methodology Why an Object Orientation?
Presentation transcript:

Chapter 6 Introduction to Design Patterns

Process Phase Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed Design x Key:= secondary emphasis x = main emphasis Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

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

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.

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 several kitchen styles. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

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 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  -- class combination and algorithm fulfilling a common design purpose. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept:  Creational Design Patterns  -- used to create objects in flexible or constrained ways. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept:  Structural Design Patterns  -- used to represent data structures such as trees, with uniform processing interfaces. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Example of Behavioral Design Goal: Port Traffic berth to drydock  obstacles 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 several kitchen styles. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

ShipTugboat 1..n1 Harbor application Customs application: reuse Ship alone ShipLongshoreman  Avoiding Dependencies Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Core Mediator Concept Applied to The Harbor Problem Ship Tugboat LeavingPort estimateTime() Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Applying the Mediator Design Pattern to The Harbor Problem ShipTugboat Vessel PortMission estimateTime() LeavingPort estimateTime() EnteringPort estimateTime() BeingMaintained estimateTime() Mediator base class Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

You have requested to view a luxury model with luxury body style, and black body color. Model Body Style Body color Choose an automobile to view. OK A Design Problem Solvable by Chain of Responsibility BasicMidsize Luxury SUV Luxury Extra Basic Black Brown Red White This part is fixed Display depends on model selected Display depends on body style selected Assume that each of these will eventually be a small, expensive animation. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept:  Behavioral Design Patterns  -- to capture behavior among objects. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Characteristics of Design Patterns 1  Viewpoints – ways to describe patterns 1.Static : class model (building blocks) 2.Dynamic : sequence or state diagram (operation)  Levels – decomposition of patterns 1.Abstract level describes the core of the pattern 2.Concrete (= non abstract) level describes the particulars of this case  Roles – the “players” in pattern usage 1.Application of the design pattern itself 2.Clients of the design pattern application 3.Setup code initializes and controls Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Characteristics of Design Patterns 2 1. Client role 2. Setup role A C A. Static viewpointB. Dynamic viewpoint 3. Role: Application of the design pattern D B (i) Abstract level (ii) Concrete level (class model) (sequence or state diagram) (class or classes) : Reference direction Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

getWallCabinet() Abstract Factory Application Sequence Diagram myStyle :KitchenStyle Client myStyle: ModernKStyle myStyle: AntiqueKStyle renderKitchen ( myStyle ) wallCabinet1: ModernWallCabinet wallCabinet1: AntiqueWallCabinet ModernWallCabinet() getWallCabinet() AntiqueWallCabinet() myStyle. getWallCabinet() -- IF myStyle BELONGS TO ModernKStyle IF myStyle BELONGS TO AntiqueKStyle -- Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept:  Two Viewpoints  We consider design patterns from the static viewpoint (what they are made from) and the dynamic viewpoint (how they function). Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Concrete and Abstract Layers KitchenStyle Kitchen Client ModernKStyle AntiqueKStyle WallCabinet FloorCabinet ModernWallCabinet ModernFloorCabinet AntiqueWallCabinet AntiqueFloorCabinet Abstract level Concrete level Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Design Goal At Work:  Correctness  We want to provide an interface to a design pattern so that its functionality is clear and separate. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept:  Two Levels  Design patterns usually have an abstract level and a non-abstract (“concrete”) level. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Design Goal At Work:  Correctness  To use design patterns effectively, we distinguish the roles involved. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

2. Client Role1. Design Pattern Application Interface to the pattern (frequently abstract; possibly several classes) DPClient DPInterface Rest of the design pattern application Interacts with the design pattern only through its interface 3. Setup Role The Three Roles Involved in Design Pattern Usage Rest of the Application No limitations Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept:  Three Roles  A part of a design either 1) applies a design pattern, 2) is a client of the pattern application, or 3) re/initializes these. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Basic Idea of Delegation requiredFunction() … intermediaryFunction( … ) { … requiredFunction() … } Client clientFunction() intermediaryFunction() replace  … clientFunction( … ) { … intermediaryFunction( … ) … } Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Basic Design Pattern Form #1: Delegation DoerBase doIt() DPInterface interfaceMethod() ConcreteDoer1 doIt() ConcreteDoer2 doIt()... doerObject … interfaceMethod( … ) { … doerObject.doIt() … } Client Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Basic Design Pattern Form #2: Recursion RecursionBase doOperation() NonrecursiveClass doOperation() RecursiveClass doOperation() void doOperation( … ) { … aggregate … } aggregate Client Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

The Recursion Form Applied to an Organization Chart Employee printOrganization() IndividualContributor printOrganization() Supervisor printOrganization() void printOrganization( … ) { … supervisees.printOrganization() … } supervisees Client Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Key Concept:  Two Forms  A design pattern’s form is usually a delegation of responsibility or a class that relates to itself (recursive). Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Summary of This Chapter  Design Patterns are recurring designs satisfying recurring design purposes  Described by Static and Dynamic Viewpoints o Typically class models and sequence diagrams respectively  Use of a pattern application is a Client Role o Client interface carefully controlled o “Setup,” typically initialization, a separate role  Design patterns Forms usually Delegation or Recursion  Classified as Creational, Structural, or Behavioral Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

Observer Design Pattern Source notify() Observer update() ConcreteSubject state ConcreteObserver observerState update() Trigger 1..n Initialize Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.