Chapter 17. GRASP General Responsibility Assignment Software Patterns (Principles) OOD: after identifying requirements, create domain model, define responsiblities.

Slides:



Advertisements
Similar presentations
GRASP: Designing Objects with Responsibilities
Advertisements

Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Object-Oriented Analysis and Design
Object-Oriented Analysis and Design CHAPTER 17, 25: GRASP PATTERNS 1.
GRASP Patterns M Taimoor Khan
Oct 2, Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
Feb R. McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Fall 2009ACS-3913 Ron McFadyen1 idea was first put forth by Christopher Alexander (1977) in his work on architectural design principles a pattern is a.
February Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m.
Object-Oriented Software Engineering Practical Software Development using UML and Java Design Patterns Sources: Chapter 6: Using Design Patterns, and Chapter.
Low Coupling High Cohesion
NJIT 1 GRASP: Designing Objects with Responsibilities Chapter 17 Applying UML and Patterns Craig Larman.
GRASP : Designing Objects with Responsibilities
October 20, 2005Architectural Design, ECEN Architectural Design Architecture Business Cycle Design for Maintainability ECEN 5543 / CSCI 5548 SW Eng.
Fall 2009ACS-3913 Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Date: 1753 an interpretation.
Feb 4, Ron McFadyen1 founded on principles of good OO design idea was first put forth by Christopher Alexander (1977) in their work concerning.
GRASP Design Patterns: Designing Objects with Responsibilities
GRASP Pattern Zhen Jiang West Chester University
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
Chapter 18 Object Design Examples with GRASP. Objectives Design use case realizations –A use-case realization describes how a particular use case is realized.
1 Chapter 17 GRASP Design Patterns: Designing Objects with Responsibilities.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
Architecture GRASP Realization of use cases in interaction diagrams Design class diagram Design ( how )
Chapter 7: Object Design Examples with GRASP. Objective Design use case realizations. Apply GRASP to assign responsibilities to classes. Apply UML to.
Chapter 26 GoF Design Patterns. The Adapter Design Pattern.
INFO 620Lecture #61 Information Systems Analysis and Design More Class Modeling; Patterns INFO 620 Glenn Booker.
BTS430 Systems Analysis and Design using UML Design Patterns.
Chapter 17. Initial Object Design Inputs: requirements meetings various Use Cases – 10% complete Key risks addressed with preliminary programming System.
GRASP: Designing Objects With Responsibilities Chapter 17 Applying UML and Patterns -Craig Larman.
Object-Oriented Analysis and Design Mar 2, 2009.
GRASP: Designing Objects With Responsibilities
Object-Oriented Analysis and Design Mar 11, 2008.
17. GRASP—Designing Objects with Responsibilities III CSE5324 Lecture Quiz 17 due at 5 PM Thursday, 8 October 2015.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
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.
Next Gen POS Example GRASP again. Same Patterns Different Example!
GRASP: Designing Objects with Responsibilities
IntellAgile Copyright © 2002 Craig Larman. All rights reserved. Object Design and Use- Case Realizations with GRASP Patterns.
What to remember from Chap 13 (Logical architecture)
Object-Oriented Analysis and Design Mar 9, 2008.
Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Patterns Roberto Damiani Mendes. Roteiro Definition; Definition; Architecture Patterns; Architecture Patterns; Design Patterns; Design Patterns; GRASP.
OO Design Roshan Chitrakar. Analysis to Design Do the RIGHT thing Do the RIGHT thing Requirement Analysis Requirement Analysis Domain Modeling with addition.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
GRASP: Designing Objects With Responsibilities
Chapter 17 Designing with Responsibilities. Fig
OO Methodology Elaboration Phase Iteration 1- Part 3.
Design. 2 The Need for Software Blueprints Knowing an object-oriented language and having access to a library is necessary but not sufficient in order.
Oct 3, Ron McFadyen1 GRASP Patterns 1.Expert 2.Creator 3.Controller 4.Low Coupling 5.High Cohesion.
General Principles in Assigning Responsibilities Responsibilities Responsibility-Driven Design CRC Cards GRASP.
OO Methodology Elaboration Phase Iteration 1- Part 2.
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 Design Examples with GRASP
GRASP – Designing Objects with Responsibilities
BTS530: Major Project Planning and Design
Chapter 12: Collaboration Diagram - PART2
Conception OBJET GRASP Patterns
DESIGN MODEL: USE-CASE REALIZATIONS WITH GRASP PATTERNS
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
GRASP : Designing Objects with Responsibilities
GoF Design Patterns (Ch. 26). GoF Design Patterns Adapter Factory Singleton Strategy Composite Façade Observer (Publish-Subscribe)
GRASP Design Patterns: Designing Objects with Responsibilities
Next Gen POS Example GRASP again.
Presentation transcript:

Chapter 17

GRASP General Responsibility Assignment Software Patterns (Principles) OOD: after identifying requirements, create domain model, define responsiblities and assign methods to classes define “messaging” (who sends the message) Patterns are a big part

Grasp Patterns Controller: go-between, UI and Domain –enhances low coupling –enhances reuse –represents “system” from the Use Case point of view –shared: User Controller handles CreateUser and DeleteUser use cases

Fig system-level operations

Fig big delegator

Fig “system” or “handler”

Fig each one handles a separate use case

Grasp Patterns Creator: not always a factory. B creates instances of A if: –B objects aggregate, record or closely use many A objects –B objects have all the info needed to create an A object When to use a factory? in cases of significant complexity (AvailableStack), conditional creation (froma family of similar classes)

Fig

Fig

Grasp Patterns High Cohesion: evaluative pattern; keep objects appropriately focused, manageable and understandable. –responsibilities are strongly related Low Cohesion: hard to comprehend, hard to reuse, hard to maintain and adverse to change

Fig

Fig

Grasp Patterns Indirection: low coupling through use of intermediary objects. –Controller is an example

Grasp Patterns Information Expert: Responsibility delegation principle –put the responsibility with the object having the most info needed to fulfill the responsibility –state the responsibility clearly first –Look in Design Model first, then the Domain Model –Expert is the most “intuitive” of patterns Who should be responsible for knowing the grand total of a sale?

Fig Domain Model Figure

Fig

Fig getTotal() needs getSubtotal(). another Expert

Fig getSubtotal() needs getPrice() yet another Expert

Grasp Patterns Low Coupling: evaluative and supports: –lower dependency between the classes, –change in one class having lower impact on other classes, –higher reuse potential.

Fig Register unnecessarily put in the middle between Sale and Payment

Fig Register not involved in Payment

Grasp Patterns Polymorphism: variation of behaviours based on type assigned to types where the variation happens: –lower dependency between the classes, –change in one class having lower impact on other classes, –higher reuse potential.

Grasp Patterns Protected Variations: protects objects from variations in other objects: –wrap the variation behind an interface facade, –adapter pattern, –uses polymorphism

Grasp Patterns Pure Fabrication: no relationship to domain objects but: – achieves low coupling, high cohesion, and the reuse potential –alternative if Information Expert not available.

Object Design Overview Iterative context. requirements workshop 2-3 fully developed use cases high risks addressed some progress on domain model

Inputs and Relationship to OOD Use Case text: visible behaviour; our object will “realize” this behaviour System Sequence Diagrams: system-level messages. These are the initial messages in our program sequence diagrams

OOD Activities: Tools: GRASP, GoF Design Patterns Metaphor: assign responsibilities to collaborating objects Modeling Purpose: Understanding, not documentation. Next slide shows some activity inputs and outputs

Fig Sale addLineItem 1

Responsibility Driven Design Responsibility: Obligation or contract Kinds of Responsibilities: –Doing: doing, initiating in others, controlling activities –Knowing: private data, related objects, calculations (guided by Domain Model and low rep'l gap –Collaboration: objects need help from otehrs Example: A Sale objects is responsible for creating a SalesLineItem object and knowing the running total

GRASP Principles A learning aid for object design based on patterns for assigning responsibilties Relationship to UML and Responsibilities Sequence Diagrams give us an opportunity to assign responsibilities

Fig Sales objects responsible for creating payment objects

What are Patterns? a software system whose design is guided by the use of general principles or idomatic solutions Pattern NameInformation Expert ProblemWhat is a basic principle by which to assign responsiblilities to objects? SolutionAssign responsibilities to the class that possesses the most information neededto fulfill it.

What are Patterns? A pattern is a named description of a (problem, solution) pair can be applied in a new context. patterns come with advice on how they should be used. Patterns are known by their names “We'll expose the services of the persistence subsystem with a Facade, use an Abstract Factory for the Mappers classes and Proxy for lazy materialization”

Example In a molopoly game what object creates (invokes creation of) the individual squares that players can land on? –B objects aggregate, record or closely use many A objects –B objects have all the info needed to create an A object A = Square ==> B = ?

Fig Creator Pattern

Fig. 17.4

Fig. 17.5

Example In a molopoly game what objects know about a Square (given a key or square name)? Such an object is an Information Expert. Again the answer is Board; this is reassuring.

Fig. 17.6

Example All other things being equal we should prefer a solution that exhibits low coupling. Low coupling tends to reduce the time, effort and defects associated with mmodifying software. Does Expert support Low Coupling?

Fig. 17.7

Example UI objects should not contain “business” logic UI objects should delegate any needed domain task to another. The Controller patter answers the question “What first object after the UI layer should receive a message from the UI layer for service?

System Sequence Diagram What class should have this responsibility?

Controller Design Controllers should either: –represent the overall system ( a device the software is running within) or a major subsystem; both variations of the Facade pattern, or –represent a use case scenario context (such as a session controller)

Fig. 17.9

Example In the monopoly game, a MonopolyGame class represents the overall system. In the ATM example the ATM represents the device the software is running within. a PlayMonopolyGameHandler acts as a Session Controller (but we only have one session!).

Fig design based on Controller

:MonopolyGame play game what next?

Example Next slide shows two design approaches possible. Either one class does all the work or else work is delegated to other classes. Lession to learn: low cohesion leads to high coupling.

Fig

Fig

Fig