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

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Chapter 6 Introduction to Design Patterns (Part I) COSC 4346: Software Engineering I Dr. Lappoon R. Tang.
18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
COP 3331 Object Oriented Analysis and Design Chapter 7 – Design by Abastraction Jean Muhammad.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 14 Structural Design Patterns SWE 316: Software Design and Architecture.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
(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.
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.
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 ( ) ( ) ( )
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
Software Waterfall Life Cycle Requirements Construction Design Testing Delivery and Installation Operations and Maintenance Concept Exploration Prototype.
Chapter 5 Design Principles II: Flexibility, Reusability, and Efficiency.
Lecture # 06 Design Principles II
Chapter 5 Design Principles II: Flexibility, Reusability, and Efficiency.
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.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
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 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.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Structural Design Patterns
ECE450S – Software Engineering II
Chapter 6 Introduction to Design Patterns. Process Phase Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed.
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.
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
Creational Patterns
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 13 Creational Design Pattern SWE 316: Software Design and Architecture.
Chapter 8 Structural Design Patterns
FACTORY METHOD. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract.
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.
Software Engineering Modern Approaches Eric Braude and Michael Bernstein 1.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Stephenson College DP 98 1 Design Patterns by Derek Peacock.
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.
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 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.
Chapter 7 Creational Design Pattern. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFrameworkDetailed.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
Introduction to Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
object oriented Principles of software design
Software Design Patterns
Software Engineering Lecture 7 - Design Patterns
Design Patterns in Game Design
Informatics 122 Software Design II
Software Design Patterns
Informatics 122 Software Design II
Chapter 8, Design Patterns Introduction
Presentation transcript:

Chapter 6 Introduction to Design Patterns

Sample Design Goals and Ways to Accomplish Them Reusability, Flexibility, and Efficiency 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.

Key Concept: Design Pattern A design pattern is a combination of classes and accompanying algorithms that fulfill a common design purpose. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

6.1 - Categories of Design Patterns

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. Factory Abstract Factory Prototype Singleton

Key Concept: Structural Design Patterns -- used to represent data structures such as linked lists or trees, with uniform processing interfaces. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission. Composite Decorator Adapter Facade Flyweight Proxy

Key Concept: Behavioral Design Patterns -- used to capture behavior among objects. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission. Chain of Responsibility Command Interpreter Mediator Observer State Template Iterator

6.2 - Example Use of a Creational Design Pattern Abstract Factory

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 ModernFloorCabinet AntiqueFloorCabinet 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 AntiqueWallCabinet AntiqueFloorCabinet 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. A design class

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.

Example of Code inside renderKitchen(KitchenStyle myStyle) // Create the wall cabinets; type is determined by the class of myStyle WallCabinet wallCabinet1 = myStyle.getWallCabinet(); WallCabinet wallCabinet2 = myStyle.getWallCabinet(); // Create the floor cabinets; type determined by the class of myStyle FloorCabinet floorCabinet1 = myStyle.getFloorCabinet(); FloorCabinet floorCabinet2 = myStyle.getFloorCabinet(); // Create the kitchen object (in the style required) Kitchen kitchen = new Kitchen(); kitchen.add(wallCabinet1,...); kitchen.add(wallCabinet2,...);... kitchen.add(floorCabinet1,...); kitchen.add(floorCabinet2,...);...

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.

6.3 - Example Use of a Behavioral Design Pattern Mediator

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.

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

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.

6.4 - Characteristics of Design Patterns

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.

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.

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.

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.

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: Three Roles Each part of a design pattern fills one of three roles: 1)Applies (i.e., instantiates) the design pattern, or 2)is a client of the pattern application, or 3)reinitializes or sets up the two previous roles 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. DP = Design Pattern

6.5 - Forms of Design Patterns

Design Pattern Forms -- Forms represent patterns to the design patterns (i.e., metapatterns) -- They consist of delegation forms and recursion forms 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 patterns form is usually either a delegation of responsibility or a class that relates to itself (recursion). 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 Classified as Creational, Structural, or Behavioral 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 are Delegation or Recursion Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.