Chapter 25 GRASP: More Objects with Responsibilities 1CS6359 Fall 2011 John Cole.

Slides:



Advertisements
Similar presentations
Chapter 11 Component-Level Design
Advertisements

Object-Oriented Analysis and Design CHAPTER 17, 25: GRASP PATTERNS 1.
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
GRASP The other four What are the first five? What is the goal/purpose of using patterns?
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
ITEC200 – Week03 Inheritance and Class Hierarchies.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
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.
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.
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
October 20, 2005Architectural Design, ECEN Architectural Design Architecture Business Cycle Design for Maintainability ECEN 5543 / CSCI 5548 SW Eng.
Object-oriented design CS 345 September 20,2002. Unavoidable Complexity Many software systems are very complex: –Many developers –Ongoing lifespan –Large.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Chapter 25 More Design Patterns.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Systems Analysis and Design in a Changing World, Fifth Edition
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
Ch:10 Component Level Design Unit 4. What is Component? A component is a modular building block for computer software Because components reside within.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Chapter 17. Initial Object Design Inputs: requirements meetings various Use Cases – 10% complete Key risks addressed with preliminary programming System.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
Design Patterns. Patterns “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution.
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
Chapter 13 Logical Architecture and UML Package Diagrams 1CS6359 Fall 2012 John Cole.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Chapter 38 Persistence Framework with Patterns 1CS6359 Fall 2011 John Cole.
IntellAgile Copyright © 2002 Craig Larman. All rights reserved. Object Design and Use- Case Realizations with GRASP Patterns.
OO Methodology Elaboration Iteration 2 - Design Patterns -
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
1 Software Engineering: A Practitioner’s Approach, 6/e Chapter 11a: Component-Level Design Software Engineering: A Practitioner’s Approach, 6/e Chapter.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
OO Design Roshan Chitrakar. Analysis to Design Do the RIGHT thing Do the RIGHT thing Requirement Analysis Requirement Analysis Domain Modeling with addition.
CHAPTER 3 MODELING COMPONENT-LEVEL DESIGN.
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
Chapter 17 Designing with Responsibilities. Fig
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Component Design Elaborating the Design Model. Component Design Translation of the architectural design into a detailed (class-based or module- based)
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Object-Oriented Analysis and Design Week 12, 2009.
11 Systems Analysis and Design in a Changing World, Fifth Edition.
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,
Object-Oriented Design
GoF Patterns (GoF) popo.
Conception OBJET GRASP Patterns
Software Engineering: A Practitioner’s Approach, 6/e Chapter 11 Component-Level Design copyright © 1996, 2001, 2005 R.S. Pressman & Associates, Inc.
TK2023 Object-Oriented Software Engineering
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
The Object Oriented Approach to Design
Component-Level Design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Software Design Lecture : 14.
Chapter 25 GRASP The other four.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Chapter 25 GRASP The other four.
GoF Patterns Ch. 26.
Object Oriented System Design Responsibilities
Presentation transcript:

Chapter 25 GRASP: More Objects with Responsibilities 1CS6359 Fall 2011 John Cole

Four More GRASP Patterns Polymorphism Indirection Pure Fabrication Protected Variations CS6359 Fall 2011 John Cole2

Polymorphism The problem is how to handle alternatives based upon a type (does this look familiar from databases?) Also, how to create pluggable software components? A related problem is pluggable software components CS6359 Fall 2011 John Cole3

Polymorphism One way to handle type-based alternatives is with conditionals: if…else or switch…case statements For example, the sqrt function has polymorphic variants for float and double (how does it really work?) (other examples?) CS6359 Fall 2011 John Cole4

Polymorphism – Pluggable Components Tax calculator uses a standard interface, the TaxCalculatorAdapter, to call any of the actual calculators. In one of my systems, I defined a set of standard methods such as getCreditLimit and the like, that interfaced to different accounting systems. CS6359 Fall 2012 John Cole5

Polymorphism Monopoly: Different square actions, therefore different classes of squares: Property – Normal, railroad, utility Tax – Income, Luxury Card – Chance, Community Chest CS6359 Fall 2011 John Cole6

7

Polymorphism What are the common methods for squares that are different depending upon type? What are properties of squares that differ by type? CS6359 Fall 2011 John Cole8

Pure Fabrication What object should have responsibility when you don’t want to violate High Cohesion and Low Coupling or other goals, but solutions offered by Expert (for example) aren’t appropriate? Having classes that represent only domain- layer concepts leads to problems. CS6359 Fall 2011 John Cole9

Pure Fabrication Assign a highly cohesive set of responsibilities to a convenience class that does not represent a domain object, but which supports high cohesion, low coupling, and reuse. Called “fabrication” because it is “made up,” not immediately obvious CS6359 Fall 2011 John Cole10

Pure Fabrication Database operations are often put in a convenience class. Saving a Sale object might, by Expert, belong in the Sale class Using a “fabricated” class increases the cohesion in Sale and reduces the coupling The idea of “persistent storage” is not a domain concept CS6359 Fall 2011 John Cole11

Another Example In Monopoly, one could have a Dice object that has properties such as the number of dice and methods to roll them and retrieve the total Would rolling and getting the total be one method or two? Why? If you’re creating games, dice are generally useful, so this class could be reused CS6359 Fall 2011 John Cole12

Object Design By representational decomposition By behavioral decomposition Most objects represent things in the problem domain, and so are derived by the former Sometimes it is useful to group methods by a behavior or algorithm, even if the resulting class doesn’t have a real-world representation CS6359 Fall 2011 John Cole13

Object Design TableOfContents would represent an actual table of contents. TableOfContentsGenerator is a pure fabrication class that creates tables of contents. CS6359 Fall 2011 John Cole14

Contraindications This can be overused. Information Expert is often a better choice, since it has the information. Use with caution. CS6359 Fall 2011 John Cole15

Indirection Pattern Problem is how to de-couple objects so that low coupling is supported and the chance of reuse is increased? A related issue is to avoid writing special-purpose code too high up in your application. Solution is to create an intermediate object that “talks” to both sides. CS6359 Fall 2011 John Cole16

Indirection Example is the TaxCalculatorAdapter. These provide a consistent interface to disparate inner objects and hide the variations “Most problems in computer science can be solved by adding another layer of indirection.” “Many performance problems can be solved by removing another layer of indirection.” CS6359 Fall 2011 John Cole17

Protected Variations Problem : How to design objects, subsystems, and systems so that the variations or instability in these elements does not have an undesirable impact on other elements. Solution: identify points of predicted variation or instability; assign responsibilities to create a stable interface around them CS6359 Fall 2011 John Cole18

Protected Variations Many other patterns and concepts in software design derive from this, including data encapsulation, polymorphism, data-driven designs, interfaces, virtual machines, etc. CS6359 Fall 2011 John Cole19

Data-Driven Designs These include techniques such as reading codes, values, class file paths, class names and so on from an external source to “parameterize” a system at run time Also includes style sheets, metadata, reading window layouts, etc. CS6359 Fall 2011 John Cole20

Protected Variations example The tax calculator problem illustrates this. The point of instability is the different interfaces of different calculators This pattern protects against variations in external APIs CS6359 Fall 2011 John Cole21

Service Lookup Includes techniques such as using naming services (like JNDI (Java Naming and Directory Interface) in Java) Protects clients from variations in the location of services Special case of data-driven design CS6359 Fall 2011 John Cole22

Interpreter-Driven Designs Include rule interpreters that execute rules read from an external source, script or language interpreters that read and run programs, virtual machines, constraint logic engines, etc. Allows changing the behavior of a system via external logic SQL stored functions; Excel formulas CS6359 Fall 2011 John Cole23

Reflective or Meta-Level Designs Getting metadata from an external source. Special case of data-driven design CS6359 Fall 2011 John Cole24

Uniform Access Syntactic construct so that both a method and field access are expressed the same way For example aCircle.radius may invoke a radius() method or simply refer to the radius field. CS6359 Fall 2011 John Cole25

Standard Languages Stick with standards CS6359 Fall 2011 John Cole26

Liskov Substitution Principle “What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T CS6359 Fall 2011 John Cole27

Liskov Substitution Principle Translating: software that refers to a type T should work properly with any subclass of T CS6359 Fall 2011 John Cole28

Don’t Talk to Strangers Original version of Protected Variations. A method should only send messages to: – The this object (self) – A parameter of the method – An attribute of this – An element of a collection which is an attribute of this – An object created within the method. CS6359 Fall 2011 John Cole29

Possible Problems with PV Overgeneralization: trying to protect against future variations by writing code that can be extended, when these variations will never happen CS6359 Fall 2011 John Cole30

Information Hiding Private variables Hide information about the design from other modules, at the points of difficulty or likely change. (David Parnas) CS6359 Fall 2011 John Cole31

Open-Closed Principle Modules should be both open (for extension) and closed (to modification in ways that affect clients.) OCP includes all software components, including methods, classes, subsystems, applications, etc. CS6359 Fall 2011 John Cole32