Chapter 25 More Design Patterns.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

Object-Oriented Analysis and Design CHAPTER 17, 25: GRASP PATTERNS 1.
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
GRASP The other four What are the first five? What is the goal/purpose of using patterns?
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
October R. McFadyen1 Polymorphism Indirection Pure Fabrication Protected Variations (Law of Demeter) Ch 22: More GRASP Patterns.
Object-Oriented Software Engineering Practical Software Development using UML and Java Design Patterns – Part 2 Sources: Chapter 6: Using Design Patterns,
Chapter 25 GRASP: More Objects with Responsibilities 1CS6359 Fall 2011 John Cole.
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Chapter 25 More Design Patterns. Polymorphism Issue: Conditional variation –If-then-else or switch statements –New variation or case: Conditional statements.
Fall 2009ACS-3913 R. McFadyen1 Polymorphism Indirection Pure Fabrication Protected Variations (Law of Demeter) More GRASP Patterns.
March 6, R. McFadyen1 Pure Fabrication P Problem: You have a responsibility to assign to a class, but assigning it to a class in the.
Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Design Patterns: someone has already.
October 20, 2005Architectural Design, ECEN Architectural Design Architecture Business Cycle Design for Maintainability ECEN 5543 / CSCI 5548 SW Eng.
March R. McFadyen1 Pure Fabrication P Problem: You have a responsibility to assign to a class, but assigning it to a class in the conceptual.
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Client/Server Software Architectures Yonglei Tao.
Objectives Design Class Diagrams Issues in system design Generalization Review UML papers.
Design Patterns.
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
1 Chapter 17 GRASP Design Patterns: Designing Objects with Responsibilities.
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
Chapter 17. Initial Object Design Inputs: requirements meetings various Use Cases – 10% complete Key risks addressed with preliminary programming System.
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Copyright © Craig Larman All Rights Reserved Responsibility-Driven Design with the GRASP Patterns.
CSSE 374: More GRASP’ing for Object Responsibilities
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.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Part VII: Design Continuous
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
CS2110: SW Development Methods Inheritance in OO and in Java Part 2: Topics: Forms of inheritance Interfaces in Java.
OO Methodology Elaboration Iteration 2 - Design Patterns -
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Elaboration Iteration 3 – Part 3 - Persistence Framework -
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain.
Object-Oriented Analysis and Design Week 12, 2009.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
1 Chapter 13: Class Diagram Chapter 19 in Applying UML and Patterns Book.
Elaboration: Iteration 2. Elaboration: Iteration 2 Basics Iteration 1 ends with : All the software has been tested: The idea in the UP is to do early,
Design Patterns: MORE Examples
BTS530: Major Project Planning and Design
GoF Patterns (GoF) popo.
Conception OBJET GRASP Patterns
CS 350 – Software Design The Strategy Pattern – Chapter 9
Behavioral Design Patterns
Week 4 Object-Oriented Programming (1): Inheritance
INTRODUCTION TO OOP Objective:
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
The Object Oriented Approach to Design
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
MSIS 670 Object-Oriented Software Engineering
Review: Design Pattern Structure
Chapter 19: Interfaces and Components
Chapter 25 GRASP The other four.
GoF Design Patterns (Ch. 26)
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Chapter 25 GRASP The other four.
Chapter 22 Object-Oriented Systems Analysis and Design and UML
GoF Patterns Ch. 26.
Presentation transcript:

Chapter 25 More Design Patterns

Issue: Conditional variation Polymorphism Issue: Conditional variation If-then-else or switch statements New variation or case: Conditional statements change Often in many places (methods, classes) Makes it difficult to extend program, add new variations Examples Alternatives based on type Pluggable software components: Replace one server with another Without affecting the clients

Example: Third-party tax calculator programs in the NextGen POS system Polymorphism Solution Do not test for the type of an object and use conditional logic Use polymorphic operations instead Example: Third-party tax calculator programs in the NextGen POS system We want to use an “adapter class” We call adapter’s methods, adapter converts it to tax calculator’s methods We’d like our code not to depend on which tax calculator we use We’d like to avoid conditional statements in the adapter class Solution: Use one adapter class per tax calculator Use polymorphism

Adapter classes implement iTaxCalculatorAdapter interface

Polymorphism in Monopoly Issue: Different actions need to be performed when player lands on different types of square Examples: Go square: Get $200 Tax square: Pay income tax (10% or $200) Regular square: Do nothing (for now) Solution: Use abstract superclass, Square RegularSquare, TaxSquare, IncomeTaxSquare subclasses

Polymorphism in Monopoly

Issue: How to adapt interaction diagrams to this change? May use “sd” and “ref” frames here to be more formal

One Polymorphic Case

Another polymorphic case

Another polymorphic case

Another polymorphic case Notice design change: Now Player knows location, instead of Piece Decreases coupling In fact, we realize “piece” class not really needed

When to use interfaces vs. abstract superclasses? Use interfaces whenever you can Becauses of single inheritance, abstract classes are restrictive Unless there are a lot of default method implementations inherited – then use abstract classes

Design Pattern: Pure Fabrication Idea: Make up (“fabricate”) new class with no direct equivalent concept in the domain When other design patterns do not offer solutions with low coupling and high cohesion Recall example: Saving a Sale object in a database What goes wrong if “Sale” saves itself? Task requires a lot of supporting database operations Sale has to be coupled to the db interface Saving to db a general task A lot of other classes need the same support Lots of duplication in each object

Solution: New “PersistentStorage” class Persistent storage not a domain concept We grouped a number of responsibilities into this class Similar issue in Monopoly: Player rolls dice: Not reusable in another game Summing of dice done by player Can’t ask for dice total without rolling again Improved design: Fabricate “Cup” class that does the jobs above

Fabrication in Monopoly: The “Cup” class

Design of objects done in one of two ways Objects chosen by representational decomposition Representing domain objects Example: TableOfContents Objects chosen by behavioral decomposition Group a number of related operations into a class Algorithm object: TableOfContentsGenerator Don’t overdo fabrication If you put all functionality in one class, you end up writing a C program

Updated Monopoly Interaction Diagram

Design Pattern: Indirection Issue: How to avoid coupling between two or more things Why? One is likely to change a lot. Don’t want the other to depend on it. Solution: Use indirection. Create intermediate object. Example: TaxCalculatorAdapter Our design is independent from the third party tax program API If the API changes, we only modify the adapter. Example: PersistentStorage Just change PersistentStorage to use a different database

Indirection via the adapter class/object

Design Pattern: Protected Variations Issue: How to design objects, subsystems and systems so that variations or instability in these elements do not have an undesirable impact on others? Solution: Identify points of predicted variations and instability Put a stable interface around them to protect the rest of the design Example: External tax calculator and the class hierarchy of adapters

Examples of Mechanisms Motivated by Protected Variations Data-driven designs: Example: Web-page style sheet read separately from the .html file Service look-up mechanisms: JNDI, Jini, UDDI Protects designs from where services are located Interpreter-Driven Designs Virtual machines, language interpreters, ... Reflective or Meta-Level Designs Java Beans A way to learn what attribute or bean property a “Bean” has and what method to use to access it

The Law of Demeter or “Don’t talk to strangers” A method should send messages only to the following objects “this” (or self) A parameter of the method An attribute of “this” An element of a collection that is an attribute of “this” An object created within the method Everyone else is a “stranger” Don’t talk to them!

Don’t talk to strangers Example of talking to strangers: public void fragileMethod() { AccountHolder holder = sale.getPayment().getAccount().getAccountHolder(); } If any object relationships change along the way, method breaks What should we do? Sale should have a method for giving us the account holder. Not a problem if object relationships are fixed. Example: Java libraries