SlideShare a Scribd company logo
© Dr. Khalid Nazim S.A. B.E., M. Tech, MBA[IT], PhD, LMISTE, LMCSI, MIE
Associate Professor,
Department of Computer Science & Information,
Majmaah University, Az- Zulfi Campus, KSA.
CS 413: Software Modeling and Analysis
Week 10
Topics to be Discussed:
 Introduction to object design
 GRASP
 Information Expert
 Creator
 Low Coupling
 High Cohesion
 Controller
“After identifying your requirements and creating a
domain model, then add methods to the software
classes, and define the messaging between the
objects to fulfill the requirements.”
But how?
1. What method belongs where?
2. How should the objects interact?
This is a critical, important, and non-trivial task
Object Design
Introduction to Object Design
Inputs :
1. Use case text :
objects are designed to realize the use cases
2. System sequence diagrams :
identify the system operation messages
3. Operation contracts :
complement the use case.
4. Supplementary Specification :
1. nonfunctional requirements
2. Glossary
5. Domain Model :
help name and attributes of software object.
Object Design
Outputs :
1. UML interaction diagram
2. Class diagram
3. Package diagrams
4. UI sketches and prototypes
5. database models
Remember : not all the input artifacts are necessary.
UP artifacts influencing OO design
Operation:
enterItem(…)
Post-conditions:
- . . .
Operation Contracts
Sale
date
. . .
Sales
LineItem
quantity
1..*
1 . . .
. . .
Domain Model
Use-Case Model
Design Model
: Register
enterItem
(itemID, quantity)
: ProductCatalog
d = getProductDescription(itemID)
addLineItem( d, quantity )
: Sale
Require-
ments
Business
Modeling
Design
Sample UP Artifact Relationships
: System
enterItem
(id, quantity)
Use Case Text
System Sequence Diagrams
make
NewSale()
system
events
Cashier
Process
Sale
: Cashier
use
case
names
system
operations
Use Case Diagram
Supplementary
Specification
Glossary
starting events to
design for, and
detailed post-
condition to
satisfy
Process Sale
1. Customer
arrives ...
2. ...
3. Cashier
enters item
identifier.
inspiration for
names of
some
software
domain
objects
functional
requirements
that must be
realized by
the objects
ideas for
the post-
conditions
Register
...
makeNewSale()
enterItem(...)
...
ProductCatalog
...
getProductDescription(...)
...
1
*
non-functional
requirements
domain rules
item details,
formats,
validation
:Book
d := getDueDate()
getDueDate message implies
Book has responsibility for
knowing its due date.
Design of behavior implies assigning
responsibilities to software classes.
Responsibilities:
contract or obligation of a classifier
Responsibility-Driven Design (RDD)
GRASP Patterns / Principles
Acronym for General Responsibility
Assignment Software Patterns
The GRASP patterns are a learning aid to
1. Help one understand essential object
design
2. Apply design reasoning in a
methodical, rational, explainable
way.
This approach to understanding and using
design principles is based on patterns of
assigning responsibilities.
What’s Responsibility
Doing:
1. Doing something itself, such as creating an object or doing a
calculation
2. Initiating action in other objects
3. Controlling and coordinating activities in other objects.
Knowing:
1. Knowing about private encapsulated data
2. Knowing about related objects
3. Knowing about things it can derive or calculate
Responsibilities and Methods
: Sale
makePayment(cashTendered)
: Payment
create(cashTendered)
abstract, implies Sale objects have a
responsibility to create Payments
Responsibility Assignment is the Key
 Appropriate assignment of responsibilities
to classes is the key to successful design.
 There are fundamental principles in
assigning responsibilities that experienced
designers apply.
 These principles are summarized in the
GRASP patterns.
GRASP:
Defines nine basic OO design principles. memorization and application of these
patterns are critical for successful object-oriented designs.
1. Creator.
2. Information Expert.
3. Controller.
4. Low Coupling.
5. High Cohesion.
6. Polymorphism.
7. Pure Fabrication.
8. Indirection.
9. Protected Variations.
Memorizing and applying
these nine principles during
every design exercise is the
primary course objective.
General Responsibility Assignment Software Patterns
GRASP Patterns
Which class, in the general case is responsible?
1. You want to assign a responsibility to a class
2. You want to avoid or minimize additional
dependencies
3. You want to maximise cohesion and minimise
coupling
4. You want to increase reuse and decrease
maintenance
5. You want to maximise understandability etc..
Creator
Who should create an instance of a particular class?
Consider assigning Class B the responsibility to create an instance of
class A if one of the following is true:
1. B contains A.
2. B aggregates A.
3. B records A.
4. B closely uses A.
Partial POS domain model
Sale
time
Sales
LineItem
quantity
Product
Description
description
price
itemID
Described-by
*
Contains
1..*
1
1
Creating a SalesLineItem
: Register : Sale
makeLineItem(quantity)
: SalesLineItem
create(quantity)
1. Sale objects are given a responsibility to create Payments.
2. The responsibility is invoked with a makePayment message
Creating a Book
:Catalog
makeBook(title)
1: create(title)
:Book
by Creator
Information Expert
What is a basic principle by which to assign responsibilities to objects?
1. Assign a responsibility to the information expert —
2. The class with the information necessary to fulfill the responsibility.
:Library
borrowResource(callNum)
1: r := getResource(callNum): Resource
:Catalog
Catalog is an information expert on
finding and returning a resource,
based on a call number. It logically
contains all of them.
by Expert
What class should be responsible for
knowing a resource, given a call number?
Applying Expert in POS Application
Start assigning responsibilities by clearly stating the responsibility.
Who should be responsible for knowing the grand total of a sale?
Where do we look for the classes that have the information needed?
1. First, in the Design Model.
2. If no relevant classes there, look in the Domain Model, and add a
corresponding software class to the Design Model.
Associations of Sale in Domain Model
Sale
time
Sales
LineItem
quantity
Product
Description
description
price
itemID
Described-by
*
Contains
1..*
1
1
Partial Interaction and Class diagrams
Sale
time
...
getTotal()
:Sale
t = getTotal
New method
1. Adding a Sale class to the Design Model supports low representational gap.
2. Express responsibility of knowing the total of a sale with the method named
getTotal.
What information do we need to know to determine the line item subtotal?
SalesLineItem is Expert for Subtotal
Sale
time
...
getTotal()
SalesLineItem
quantity
getSubtotal()
New method
1 *: st = getSubtotal
: Sale
t = getTotal lineItems[ i ] :
SalesLineItem
this notation will imply we
are iterating over all
elements of a collection
How does the SalesLineItem find out the product price?
“Partial” information experts collaborate to fulfill the responsibility.
Product Description is Expert for Price
Sale
time
...
getTotal()
SalesLineItem
quantity
getSubtotal()
Product
Description
description
price
itemID
getPrice()
New method
:Product
Description
1.1: p := getPrice()
1 *: st = getSubtotal
: Sale
t = getTotal lineItems[ i ] :
SalesLineItem
GRASP_Designing Objects With Responsibilities.pdf
The Low Coupling Principle
Problem : Reduce the impact of change.
Solution: Assign responsibilities so that coupling remains low.
Use this principle to evaluate alternatives.
Coupling: how strongly one element is connected to, has knowledge of,
or relies on other elements.
1. Low coupling tends to reduce the time, effort, and defects in
modifying software.
2. Coupling per se is not a problem, only coupling to elements that
are unstable (likely to change).
Low Coupling in POS Case Study
What class should be responsible for creating a Payment instance
and associating it with the Sale?
1. Register?
2. Sale?
Creator pattern suggests Register should create the Payment.
A register records a payment in the real world.
Register creates Payment
: Register p : Payment
:Sale
makePayment() 1: create()
2: addPayment(p)
Register is coupled to both Sale and Payment.
Sale creates Payment
: Register :Sale
:Payment
makePayment() 1: makePayment()
1.1. create()
• Assuming that the Sale must eventually be coupled to
knowledge of a Payment, having Sale create the
Payment does not increase coupling.
– Low Coupling and Creator suggest different solutions.
Common Forms of Coupling in OO Languages
1. Type X has an attribute (data member, instance variable) that refers
to type Y or an instance of Y.
2. An object of type X calls on services of a type Y object.
3. Type X has a method that references an instance of type Y
(e.g., parameter, local variable, object returned from a method).
4. Type X is a subclass of type Y.
5. Type X implements the interface Y.
Controller Pattern
What first object beyond the UI layer receives and coordinates (“controls”) a
system operation message?
Solution:
Assign the responsibility to a class that represents one of the following options:
Option 1a: Represents the overall system or a root object.
E.g., an object called MonopolyGame.
Option 1b: Represents the device the software is running within.
E.g., Phone or BankCashMachine.
Not applicable in the Monopoly case.
Option 2: Represents the use case or session.
E.g., PlayMonopolyGameHandler.
Remind from analysis:
System Operations of POS Application
System Operations of POS Application
System
endSale()
enterItem()
makeNewSale()
makePayment()
. . .
During analysis, system operations may be
assigned to a System class.
1. Does not mean a software class
named System fulfills the system
operations during design.
2. During design, a controller class is
assigned the responsibility for
system operations.
What should be Controller for enterItem?
Controller choices ?
:Register
enterItem(id, quantity)
:ProcessSaleHandler
enterItem(id, quantity)
1. In the POS domain, Register (POS Terminal) is a specialized device
with software running on it.
2. ProcessSaleHandler represents a receiver of all system events of a
use case scenario.
Allocation of System Operations
Register
...
endSale()
enterItem()
makeNewSale()
makePayment()
makeNewReturn()
enterReturnItem()
. . .
System
endSale()
enterItem()
makeNewSale()
makePayment()
makeNewReturn()
enterReturnItem()
. . .
system operations
discovered during system
behavior analysis
allocation of system
operations during design,
using one facade controller
ProcessSale
Handler
...
endSale()
enterItem()
makeNewSale()
makePayment()
System
endSale()
enterItem()
makeNewSale()
makePayment()
enterReturnItem()
makeNewReturn()
. . .
allocation of system
operations during design,
using several use case
controllers
HandleReturns
Handler
...
enterReturnItem()
makeNewReturn()
. . .
During design, system operations identified during system behaviour analysis are
assigned to one or more controller classes.
Delegation
UI layer objects delegate system events to another layer.
1. UI layer shouldn’t contain application logic.
2. Increases potential for reuse.
3. Can “unplug” UI layer – use a different framework or run in
offline “batch” mode.
Controller should delegate the work that needs to be done to other
objects.
 It controls or coordinates the activity.
Desirable coupling of UI and domain layers
Undesirable coupling of UI to domain layer
Facade(Front/ Cover) Controller
Facade controller represents the overall system, device, or subsystem.
1. A façade or cover over other layers.
2. Abstraction of overall physical unit
e.g., Register, TelecommSwitch, Robot, or
3. Class representing entire system or concept
e.g., POSSystem, ChessGame.
4. Suitable when there are not too many system events or when UI
cannot choose between multiple controllers.
Use Case Controller
A use case controller handles system events for a single use case.
1. Can maintain information about the state of the use case.
E.g., detect out-of-sequence system events.
2. Different controller for each use case.
3. Not a domain object, but artificial construct (“pure fabrication”) to
support the system.
4. Use when there are many system events.
5. Factors handling into separate classes.
:Library
borrowResource(callNum)
by Controller
Controller - Facades
1. Facades are “covers.”
2. Intent - A class that (in some way) represents an overall cover.
3. Many possibilities.
Example: The entire organization.
:LibSystem
borrowResource(callNum)
:LibInfoSystem
borrowResource(callNum)
Controller - Facades
Other facades? A class representing the “system.”
Examples:
1. The software information system.
2. The device that includes a computer and software such as an ATM.
High Cohesion
Solution
Assign a responsibility so that cohesion remains high
Problem
How to keep complexity manageable?
Cohesion is a measure of how strongly related and focused the responsibilities of an
element (classes, subsystems) are
A class with low cohesion does many unrelated things, or does too much work
They suffer from the following problems:
1. hard to understand
2. hard to reuse
3. hard to maintain
4. delicate; constantly effected by change
Benefits of High Cohesion
1. Clarity and ease of comprehension of the design is increased.
2. Maintenance and enhancements are simplified.
3. Low coupling is often supported.
4. The fine grain of highly related functionality supports increased
reuse because a cohesive class can be used for a very specific
purpose.
Reduced cohesion of Register(creator pattern)
: Register : Sale
addPayment( p )
p : Payment
create()
makePayment()
Low cohesion:
Register is taking part of the responsibility for fulfilling “makePayment” operation and
many other unrelated responsibility ( 50 system operations all received by Register).then it
will become burden with tasks and become incohesive
Higher Cohesion and Lower Coupling
: Register : Sale
makePayment()
: Payment
create()
makePayment()
Solution:
Delegate the payment creation responsibility to “Sale” to support high cohesion
 In Object-Oriented Analysis and Design (OOAD), General Responsibility
Assignment Software Patterns (GRASP) play a crucial role in designing effective
and maintainable software systems.
 GRASP offers a set of guidelines to aid developers in assigning responsibilities to
classes and objects in a way that promotes low coupling, high cohesion, and overall
robustness.
 By understanding and applying GRASP principles, developers can create software
solutions that are flexible, scalable, and easier to maintain over time.
Summary
GRASP_Designing Objects With Responsibilities.pdf

More Related Content

PDF
CS8592-OOAD Lecture Notes Unit-4
PPTX
Software Design And ArchitectureLecture-4.pptx
PPT
Object Oriented Analysis and Design with UML2 part2
PDF
Grasp oose week 14.pdf
PPT
Final grasp ASE
PPTX
Patterns of Assigning Responsibilities
PPT
Week3 to-design
CS8592-OOAD Lecture Notes Unit-4
Software Design And ArchitectureLecture-4.pptx
Object Oriented Analysis and Design with UML2 part2
Grasp oose week 14.pdf
Final grasp ASE
Patterns of Assigning Responsibilities
Week3 to-design

Similar to GRASP_Designing Objects With Responsibilities.pdf (20)

PDF
OO design principles and patterns
PPTX
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
PPTX
Grasp principles
PDF
A&D - Object Oriented Design using UML
PPT
chapter-4-objected-oriented analysis and design with UML.ppt
PDF
Responsibility Driven Design
PPTX
Object Oriented System Design
DOCX
ContentsPhase 1 Design Concepts2Project Description2Use.docx
PPT
Object Oriented Design
PPT
Object Oriented Design
PPTX
Software Development: Beyond Training wheels
PPT
Ood Post1
PPTX
Software Design principales
PPT
Week4 grasp-into
PPT
8. design patterns
 
PPTX
Domain Driven Design
PPTX
Same Patterns, Different Architectures
PPTX
Establishing a SOLID Foundation
PDF
SOAT Agile Day 2017 DDD
OO design principles and patterns
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
Grasp principles
A&D - Object Oriented Design using UML
chapter-4-objected-oriented analysis and design with UML.ppt
Responsibility Driven Design
Object Oriented System Design
ContentsPhase 1 Design Concepts2Project Description2Use.docx
Object Oriented Design
Object Oriented Design
Software Development: Beyond Training wheels
Ood Post1
Software Design principales
Week4 grasp-into
8. design patterns
 
Domain Driven Design
Same Patterns, Different Architectures
Establishing a SOLID Foundation
SOAT Agile Day 2017 DDD
Ad

More from nazimsattar (20)

PPTX
how to build a simple operating system type
PPTX
operating system Evolution understanding the basics
PPT
working with internet technologies using XML
PPT
working with internet technologies using CSS
PPT
different Data_Analysis concepts in data science
PPT
Data Munging in concepts of data mining in DS
PDF
Class diagram and its importance in software
PPT
Memory management principles in operating systems
PPT
Deadlock principles in operating systems
PDF
overview of natural language processing concepts
PDF
introduction to natural language processing
PPT
HCI_usable_user_interface_productivity in HCI
PPT
HCI_user_interaction_Design_interaction design
PPT
Introduction to the operating and its types
PPT
Operating systems structures and their practical applications
PPT
Block_Chain_Technology and its concepts in reality
PPT
Edge Computing and its related technologies
PPTX
The Real time applications of Virtual Reality
PPTX
Marketing of AI technology in real life examples
PPT
system analysis and design used in software
how to build a simple operating system type
operating system Evolution understanding the basics
working with internet technologies using XML
working with internet technologies using CSS
different Data_Analysis concepts in data science
Data Munging in concepts of data mining in DS
Class diagram and its importance in software
Memory management principles in operating systems
Deadlock principles in operating systems
overview of natural language processing concepts
introduction to natural language processing
HCI_usable_user_interface_productivity in HCI
HCI_user_interaction_Design_interaction design
Introduction to the operating and its types
Operating systems structures and their practical applications
Block_Chain_Technology and its concepts in reality
Edge Computing and its related technologies
The Real time applications of Virtual Reality
Marketing of AI technology in real life examples
system analysis and design used in software
Ad

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Insiders guide to clinical Medicine.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
Renaissance Architecture: A Journey from Faith to Humanism
VCE English Exam - Section C Student Revision Booklet
Insiders guide to clinical Medicine.pdf
Anesthesia in Laparoscopic Surgery in India
O7-L3 Supply Chain Operations - ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Complications of Minimal Access Surgery at WLH
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Pre independence Education in Inndia.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
TR - Agricultural Crops Production NC III.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
human mycosis Human fungal infections are called human mycosis..pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
Abdominal Access Techniques with Prof. Dr. R K Mishra

GRASP_Designing Objects With Responsibilities.pdf

  • 1. © Dr. Khalid Nazim S.A. B.E., M. Tech, MBA[IT], PhD, LMISTE, LMCSI, MIE Associate Professor, Department of Computer Science & Information, Majmaah University, Az- Zulfi Campus, KSA. CS 413: Software Modeling and Analysis
  • 2. Week 10 Topics to be Discussed:  Introduction to object design  GRASP  Information Expert  Creator  Low Coupling  High Cohesion  Controller
  • 3. “After identifying your requirements and creating a domain model, then add methods to the software classes, and define the messaging between the objects to fulfill the requirements.” But how? 1. What method belongs where? 2. How should the objects interact? This is a critical, important, and non-trivial task Object Design
  • 4. Introduction to Object Design Inputs : 1. Use case text : objects are designed to realize the use cases 2. System sequence diagrams : identify the system operation messages 3. Operation contracts : complement the use case. 4. Supplementary Specification : 1. nonfunctional requirements 2. Glossary 5. Domain Model : help name and attributes of software object.
  • 5. Object Design Outputs : 1. UML interaction diagram 2. Class diagram 3. Package diagrams 4. UI sketches and prototypes 5. database models Remember : not all the input artifacts are necessary.
  • 6. UP artifacts influencing OO design Operation: enterItem(…) Post-conditions: - . . . Operation Contracts Sale date . . . Sales LineItem quantity 1..* 1 . . . . . . Domain Model Use-Case Model Design Model : Register enterItem (itemID, quantity) : ProductCatalog d = getProductDescription(itemID) addLineItem( d, quantity ) : Sale Require- ments Business Modeling Design Sample UP Artifact Relationships : System enterItem (id, quantity) Use Case Text System Sequence Diagrams make NewSale() system events Cashier Process Sale : Cashier use case names system operations Use Case Diagram Supplementary Specification Glossary starting events to design for, and detailed post- condition to satisfy Process Sale 1. Customer arrives ... 2. ... 3. Cashier enters item identifier. inspiration for names of some software domain objects functional requirements that must be realized by the objects ideas for the post- conditions Register ... makeNewSale() enterItem(...) ... ProductCatalog ... getProductDescription(...) ... 1 * non-functional requirements domain rules item details, formats, validation
  • 7. :Book d := getDueDate() getDueDate message implies Book has responsibility for knowing its due date. Design of behavior implies assigning responsibilities to software classes. Responsibilities: contract or obligation of a classifier Responsibility-Driven Design (RDD)
  • 8. GRASP Patterns / Principles Acronym for General Responsibility Assignment Software Patterns The GRASP patterns are a learning aid to 1. Help one understand essential object design 2. Apply design reasoning in a methodical, rational, explainable way. This approach to understanding and using design principles is based on patterns of assigning responsibilities.
  • 9. What’s Responsibility Doing: 1. Doing something itself, such as creating an object or doing a calculation 2. Initiating action in other objects 3. Controlling and coordinating activities in other objects. Knowing: 1. Knowing about private encapsulated data 2. Knowing about related objects 3. Knowing about things it can derive or calculate
  • 10. Responsibilities and Methods : Sale makePayment(cashTendered) : Payment create(cashTendered) abstract, implies Sale objects have a responsibility to create Payments
  • 11. Responsibility Assignment is the Key  Appropriate assignment of responsibilities to classes is the key to successful design.  There are fundamental principles in assigning responsibilities that experienced designers apply.  These principles are summarized in the GRASP patterns.
  • 12. GRASP: Defines nine basic OO design principles. memorization and application of these patterns are critical for successful object-oriented designs. 1. Creator. 2. Information Expert. 3. Controller. 4. Low Coupling. 5. High Cohesion. 6. Polymorphism. 7. Pure Fabrication. 8. Indirection. 9. Protected Variations. Memorizing and applying these nine principles during every design exercise is the primary course objective. General Responsibility Assignment Software Patterns
  • 13. GRASP Patterns Which class, in the general case is responsible? 1. You want to assign a responsibility to a class 2. You want to avoid or minimize additional dependencies 3. You want to maximise cohesion and minimise coupling 4. You want to increase reuse and decrease maintenance 5. You want to maximise understandability etc..
  • 14. Creator Who should create an instance of a particular class? Consider assigning Class B the responsibility to create an instance of class A if one of the following is true: 1. B contains A. 2. B aggregates A. 3. B records A. 4. B closely uses A.
  • 15. Partial POS domain model Sale time Sales LineItem quantity Product Description description price itemID Described-by * Contains 1..* 1 1
  • 16. Creating a SalesLineItem : Register : Sale makeLineItem(quantity) : SalesLineItem create(quantity) 1. Sale objects are given a responsibility to create Payments. 2. The responsibility is invoked with a makePayment message
  • 17. Creating a Book :Catalog makeBook(title) 1: create(title) :Book by Creator
  • 18. Information Expert What is a basic principle by which to assign responsibilities to objects? 1. Assign a responsibility to the information expert — 2. The class with the information necessary to fulfill the responsibility. :Library borrowResource(callNum) 1: r := getResource(callNum): Resource :Catalog Catalog is an information expert on finding and returning a resource, based on a call number. It logically contains all of them. by Expert What class should be responsible for knowing a resource, given a call number?
  • 19. Applying Expert in POS Application Start assigning responsibilities by clearly stating the responsibility. Who should be responsible for knowing the grand total of a sale? Where do we look for the classes that have the information needed? 1. First, in the Design Model. 2. If no relevant classes there, look in the Domain Model, and add a corresponding software class to the Design Model.
  • 20. Associations of Sale in Domain Model Sale time Sales LineItem quantity Product Description description price itemID Described-by * Contains 1..* 1 1
  • 21. Partial Interaction and Class diagrams Sale time ... getTotal() :Sale t = getTotal New method 1. Adding a Sale class to the Design Model supports low representational gap. 2. Express responsibility of knowing the total of a sale with the method named getTotal. What information do we need to know to determine the line item subtotal?
  • 22. SalesLineItem is Expert for Subtotal Sale time ... getTotal() SalesLineItem quantity getSubtotal() New method 1 *: st = getSubtotal : Sale t = getTotal lineItems[ i ] : SalesLineItem this notation will imply we are iterating over all elements of a collection How does the SalesLineItem find out the product price? “Partial” information experts collaborate to fulfill the responsibility.
  • 23. Product Description is Expert for Price Sale time ... getTotal() SalesLineItem quantity getSubtotal() Product Description description price itemID getPrice() New method :Product Description 1.1: p := getPrice() 1 *: st = getSubtotal : Sale t = getTotal lineItems[ i ] : SalesLineItem
  • 25. The Low Coupling Principle Problem : Reduce the impact of change. Solution: Assign responsibilities so that coupling remains low. Use this principle to evaluate alternatives. Coupling: how strongly one element is connected to, has knowledge of, or relies on other elements. 1. Low coupling tends to reduce the time, effort, and defects in modifying software. 2. Coupling per se is not a problem, only coupling to elements that are unstable (likely to change).
  • 26. Low Coupling in POS Case Study What class should be responsible for creating a Payment instance and associating it with the Sale? 1. Register? 2. Sale? Creator pattern suggests Register should create the Payment. A register records a payment in the real world.
  • 27. Register creates Payment : Register p : Payment :Sale makePayment() 1: create() 2: addPayment(p) Register is coupled to both Sale and Payment.
  • 28. Sale creates Payment : Register :Sale :Payment makePayment() 1: makePayment() 1.1. create() • Assuming that the Sale must eventually be coupled to knowledge of a Payment, having Sale create the Payment does not increase coupling. – Low Coupling and Creator suggest different solutions.
  • 29. Common Forms of Coupling in OO Languages 1. Type X has an attribute (data member, instance variable) that refers to type Y or an instance of Y. 2. An object of type X calls on services of a type Y object. 3. Type X has a method that references an instance of type Y (e.g., parameter, local variable, object returned from a method). 4. Type X is a subclass of type Y. 5. Type X implements the interface Y.
  • 30. Controller Pattern What first object beyond the UI layer receives and coordinates (“controls”) a system operation message? Solution: Assign the responsibility to a class that represents one of the following options: Option 1a: Represents the overall system or a root object. E.g., an object called MonopolyGame. Option 1b: Represents the device the software is running within. E.g., Phone or BankCashMachine. Not applicable in the Monopoly case. Option 2: Represents the use case or session. E.g., PlayMonopolyGameHandler.
  • 31. Remind from analysis: System Operations of POS Application
  • 32. System Operations of POS Application System endSale() enterItem() makeNewSale() makePayment() . . . During analysis, system operations may be assigned to a System class. 1. Does not mean a software class named System fulfills the system operations during design. 2. During design, a controller class is assigned the responsibility for system operations.
  • 33. What should be Controller for enterItem?
  • 34. Controller choices ? :Register enterItem(id, quantity) :ProcessSaleHandler enterItem(id, quantity) 1. In the POS domain, Register (POS Terminal) is a specialized device with software running on it. 2. ProcessSaleHandler represents a receiver of all system events of a use case scenario.
  • 35. Allocation of System Operations Register ... endSale() enterItem() makeNewSale() makePayment() makeNewReturn() enterReturnItem() . . . System endSale() enterItem() makeNewSale() makePayment() makeNewReturn() enterReturnItem() . . . system operations discovered during system behavior analysis allocation of system operations during design, using one facade controller ProcessSale Handler ... endSale() enterItem() makeNewSale() makePayment() System endSale() enterItem() makeNewSale() makePayment() enterReturnItem() makeNewReturn() . . . allocation of system operations during design, using several use case controllers HandleReturns Handler ... enterReturnItem() makeNewReturn() . . . During design, system operations identified during system behaviour analysis are assigned to one or more controller classes.
  • 36. Delegation UI layer objects delegate system events to another layer. 1. UI layer shouldn’t contain application logic. 2. Increases potential for reuse. 3. Can “unplug” UI layer – use a different framework or run in offline “batch” mode. Controller should delegate the work that needs to be done to other objects.  It controls or coordinates the activity.
  • 37. Desirable coupling of UI and domain layers
  • 38. Undesirable coupling of UI to domain layer
  • 39. Facade(Front/ Cover) Controller Facade controller represents the overall system, device, or subsystem. 1. A façade or cover over other layers. 2. Abstraction of overall physical unit e.g., Register, TelecommSwitch, Robot, or 3. Class representing entire system or concept e.g., POSSystem, ChessGame. 4. Suitable when there are not too many system events or when UI cannot choose between multiple controllers.
  • 40. Use Case Controller A use case controller handles system events for a single use case. 1. Can maintain information about the state of the use case. E.g., detect out-of-sequence system events. 2. Different controller for each use case. 3. Not a domain object, but artificial construct (“pure fabrication”) to support the system. 4. Use when there are many system events. 5. Factors handling into separate classes.
  • 41. :Library borrowResource(callNum) by Controller Controller - Facades 1. Facades are “covers.” 2. Intent - A class that (in some way) represents an overall cover. 3. Many possibilities. Example: The entire organization.
  • 42. :LibSystem borrowResource(callNum) :LibInfoSystem borrowResource(callNum) Controller - Facades Other facades? A class representing the “system.” Examples: 1. The software information system. 2. The device that includes a computer and software such as an ATM.
  • 43. High Cohesion Solution Assign a responsibility so that cohesion remains high Problem How to keep complexity manageable? Cohesion is a measure of how strongly related and focused the responsibilities of an element (classes, subsystems) are A class with low cohesion does many unrelated things, or does too much work They suffer from the following problems: 1. hard to understand 2. hard to reuse 3. hard to maintain 4. delicate; constantly effected by change
  • 44. Benefits of High Cohesion 1. Clarity and ease of comprehension of the design is increased. 2. Maintenance and enhancements are simplified. 3. Low coupling is often supported. 4. The fine grain of highly related functionality supports increased reuse because a cohesive class can be used for a very specific purpose.
  • 45. Reduced cohesion of Register(creator pattern) : Register : Sale addPayment( p ) p : Payment create() makePayment() Low cohesion: Register is taking part of the responsibility for fulfilling “makePayment” operation and many other unrelated responsibility ( 50 system operations all received by Register).then it will become burden with tasks and become incohesive
  • 46. Higher Cohesion and Lower Coupling : Register : Sale makePayment() : Payment create() makePayment() Solution: Delegate the payment creation responsibility to “Sale” to support high cohesion
  • 47.  In Object-Oriented Analysis and Design (OOAD), General Responsibility Assignment Software Patterns (GRASP) play a crucial role in designing effective and maintainable software systems.  GRASP offers a set of guidelines to aid developers in assigning responsibilities to classes and objects in a way that promotes low coupling, high cohesion, and overall robustness.  By understanding and applying GRASP principles, developers can create software solutions that are flexible, scalable, and easier to maintain over time. Summary