Four More GRASP Principles CSSE 574: Session 5, Part 2

Similar documents
2009 Shawn A. Bohner. Shawn Bohner Office: Moench Room F212 Phone: (812)

GRASP 2. CSC 440: Software Engineering Slide #1

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

GRASP ing at the First 5 Patterns Principles CSSE 574: Session 3, Part 4

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

Object-Oriented Design II - GRASP

Eliminate enterprise software design instability - protect variations! Nickolay Kofanov

GRASP: MORE PATTERNS FOR

From Design Patterns: Elements of Reusable Object Oriented Software. Read the sections corresponding to patterns covered in the following slides.

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

PART 4 Elaboration Iteration 2 More Patterns

Object-Oriented Design

Object-Oriented Design

GRASP Design Patterns A.A. 2018/2019

Object-Oriented Design I

Domain Modeling. CSSE 574: Week 1, Part 3. Steve Chenoweth Phone: Office (812) Cell (937)

On to Iteration 3, and Activity Diagrams CSSE 574: Session 6, Part 1

Object-Oriented Design II

OODP OOAD Session 7a

OODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Domain Modeling: Associations and Attributes

17. GRASP: Designing Objects with Responsibilities

Principles of Software Construction: Objects, Design, and Concurrency

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

CSSE 374: GRASP ing at the First Five Patterns Principles. Shawn Bohner Office: Moench Room F212 Phone: (812)

More Object Design with GoF Patterns CSSE 574: Session 7, Part 2

Final Exam CISC 475/675 Fall 2004

Software Engineering

Software Engineering

Domain Analysis. SWEN-261 Introduction to Software Engineering. Department of Software Engineering Rochester Institute of Technology.

Avancier Methods. Very basic design patterns. It is illegal to copy, share or show this document

CAS 703 Software Design

Chapter 8: Class and Method Design

More Object Design with GoF Patterns (continued) CSSE 574: Session 7, Part 3

Tecniche di Progettazione: Design Patterns

Persistence Frameworks with GoF Patterns (State & Command) CSSE 574: Session 7, Part 4

Object Analysis & Design in the textbook. Introduction to GRASP: Assigning Responsibilities to Objects. Responsibility-Driven Design

Introduction - SENG 330. Object-Oriented Analysis and Design

Responsibilities. Using several specific design principles to guide OO design decisions.

Applying Some More Gang of Four Design Patterns CSSE 574: Session 5, Part 4

Principles of Software Construction: Objects, Design and Concurrency. Object-Oriented Design: Assigning Responsibilities.

1: Introduction to Object (1)

11/2/09. Code Critique. What goal are we designing to? What is the typical fix for code smells? Refactoring Liskov Substitution Principle

A4 Explain how the Visitor design pattern works (4 marks)

Object-Oriented Concepts and Design Principles

Object Oriented. Analysis and Design

The Design Patterns Matrix From Analysis to Implementation

Principles of Software Construction: Objects, Design, and Concurrency

18.1 Definitions and General OO Principles

Lecture: Modular Design

Topics. Software Process. Agile. Requirements. Basic Design. Modular Design. Design Patterns. Testing. Quality. Refactoring.

Assigning Responsibilities

Setting the stage... Key Design Issues. Main purpose - Manage software system complexity by improving software quality factors

ADVANCED SOFTWARE DESIGN LECTURE 4 SOFTWARE ARCHITECTURE

Modularity Guidelines for design in any programming language

Design and Information Hiding

Logical Architecture & Design Preliminaries

Ingegneria del Software Corso di Laurea in Informatica per il Management. Software quality and Object Oriented Principles

Information Expert (or Expert)

Object-Oriented Design I - SOLID

The following topics will be covered in this course (not necessarily in this order).

Patterns and Testing

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

References: Applying UML and patterns Craig Larman

PROCESS DEVELOPMENT METHODOLOGY The development process of an API fits the most fundamental iterative code development

Object- Oriented Design with UML and Java Part I: Fundamentals

Modularity!! Guidelines for design! in any programming language!

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Magento Technical Guidelines

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod

COMP 6471 Software Design Methodologies

Summary of the course lectures

Intro to: Design Principles

Design patterns. Jef De Smedt Beta VZW

Operations Contracts and Preliminaries on Design

Software Engineering Principles

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

17.11 Bean Rules persistent

Inheritance and object compatibility

Structured Analysis and Design

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING CS2353-OBJECT ORIENTED ANALYSIS AND DESIGN. Unit-I. Introduction to OOAD

Chapter 5 Object-Oriented Programming

Chapter 10 Object-Oriented Design Principles

Originality is Overrated: OO Design Principles

DNSSEC Deployment Issues

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Architectural Patterns

security model. The framework allowed for quickly creating applications that examine nancial data stored in a database. The applications that are gene

Design Patterns. Architectural Patterns. Contents of a Design Pattern. Dr. James A. Bednar. Dr. David Robertson

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

OBJECT ORIENTED ANALYSIS AND DESIGN SYLLABUS

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

CSE 70 Final Exam Fall 2009

Principles of Object-Oriented Design

Software Engineering CSC40232: SOFTWARE ENGINEERING. Guest Lecturer: Jin Guo SOLID Principles sarec.nd.edu/courses/se2017

Transcription:

Four More GRASP Principles CSSE 574: Session 5, Part 2 Steve Chenoweth Phone: Office (812) 877-8974 Cell (937) 657-3885 Email: chenowet@rose-hulman.edu

GRASP II And Furthermore Polymorphism Indirection Pure Fabrication Protected Variations 2

Polymorphism Problem: How do we handle alternatives based on type? Chained ifs and lots of switch statements are a bad code smell new types require finding conditions and editing How do we create pluggable software components Pluggable components require swapping one module for another without changing surrounding design Solution: When related alternatives vary by type, assign responsibility to the types for which the behaviors are varying. Use subtypes and polymorphic methods Eliminates lots of conditional logic based on type Corollary: Avoid instanceof tests

Polymorphism Example Bad: switch (square.gettype()) { case GO: case INCOME_TAX: case GO_TO_JAIL: default: } What happens when we need to add other sorts of squares in future iterations? Solution: Replace switch with polymorphic method call

Monopoly Polymorphism Example 5

Polymorphism Example (continued) Make abstract unless clear default behavior Details of polymorphic method drawn separately

Monopoly Polymorphism Example 7

Monopoly Polymorphism Example 8

Monopoly Polymorphism Example 9

Monopoly Polymorphism Example 10

Polymorphism Observations Using polymorphism indicates that Piece class not needed since it s a proxy for the Player A design using Polymorphism can be easily extended for new variations When should supertype be an interface? Don t want to commit to a class hierarchy Need to reduce coupling Contraindication: Polymorphism can be over used speculative future-proofing Don t be too clever!

Your Project & Polymorphism identify a situation in your project where Polymorphism might be applicable. If no such situation exists, try to come up with an extension to your system that might use Polymorphism. What method(s) would behave differently for the different subtypes?

Pure Fabrication Problem: What object should have responsibility when solutions for low representation gap (like Info. Expert) lead us astray (i.e., into high coupling and low cohesion) Solution: Assign a cohesive set of responsibilities to an artificial (not in the domain model) class

Monopoly Pure Fabrication Example How do we model the player rolling the dice? If Player rolls dice, then dice rolling behavior not very reusable How do we provide something that would be more reusable? Player Cup 1 Cup Roll gettotal Dice * {ordered} Die Face Value Role getfv Pure Fabrication 14

Monopoly Pure Fabrication Example 15

Common Design Strategies Representational decomposition Lowering the representation gap (noun-based) Behavioral decomposition Centered around behaviors (verb-based) Pure Fabrications are often behavioral decompositions

Pure Fabrication Observations Benefits: Higher cohesion Greater potential for reuse Contraindications: Can be abused to create too many behavior objects Watch for data being passed to other objects for calculations Keep operations with data unless you have a good reason not to

Cartoon of the Day Used with permission. http://notinventedhe.re/on/2009-10-13

Indirection Problem: Where do we assign responsibility if we want to avoid direct coupling between two or more objects? Solution: Assign responsibility to an intermediate object to mediate between the other components There is no problem in computer science that cannot be solved by an extra level of indirection. David Wheeler (David Wheeler got the first PhD in computer science!)

Indirection & Polymorphism Example «interface» ITaxCalculatorAdapter gettaxes( Sale ) : List<TaxLineItems> TaxMasterAdapter gettaxes( Sale ) : List<TaxLineItems> GoodAsGoldTaxPro Adapter gettaxes( Sale ) : List<TaxLineItems>...... <???>Adapter By Polymorphism, multiple tax calculator adapters have their own similar, but varying behavior for adapting to different external tax calculators. 20

NexGen POS Indirection Example : Sale :TaxMasterAdapter t = gettotal... taxes = gettaxes( s ) TCP socket communication xxx... «actor» :TaxMasterSystem the adapter acts as a level of indirection to external systems TaxMasterAdapter is a Pure Fabrication offering a level of Indirection Shields client (Sale) from variable server (proprietary tax calculator system) 21

Protected Variation Problem: How do we design objects and systems so that instability in them does not have undesirable effects on other elements? Solution: Identify points of predicted instability (variation) and assign responsibilities to create a stable interface around them

Protected Variation Pervasive in Computing Virtual machines and operating systems Data-driven designs (e.g., configuration files) Service lookup (URLs, DNS) Uniform access to methods/fields (Ada, Eiffel, C#, Objective-C, Ruby, ) Standard languages (SQL) Liskov Substitution Principle Methods of a subtype must have (at least) the expected behavior of overridden methods

Protected Variations: Observations When to use it? Variation point is a known area where clients need to be protected from variable servers Evolution point is an area where future variation may occur Should we invest in protecting against future variation? How likely is it to occur? If it is, then should probably use PV now If unlikely, then should probably defer using PV 24

Law of Demeter, or Don t Talk to Strangers Within a method, messages should only be sent to: this a parameter field of this element in collection of field of this new objects Better: Don t talk to strangers who seem unstable This guideline warns against code like: sale.getpayment().getaccount().getaccountholder() Pic above is all over the web. I found it at http://www.html4.com/mime/markup/html/will.html.

Protected Variations Observations Benefits (if we guessed variation points correctly): Extensions easy to add Can plug in new implementations Lower coupling Lower cost of change Risk: watch out for speculative futureproofing

Protected Variations by Other Names Information hiding [Parnas72] We propose instead that one begins with a list of difficult design decisions which are likely to change. Each module is then designed to hide such a decision from the others. Open-Closed Principle [Meyer88] Modules should be both open (for extension ) and closed ( to modification[s] that affect clients)