8/3/2019 GRASP Pattern n
1/17
GRASP PatternGRASP Pattern
8/3/2019 GRASP Pattern n
2/17
Outline
Outline
Introduction
Information Expert Creator
Low Coupling
High Cohesion Controller
8/3/2019 GRASP Pattern n
3/17
Introd
uction
Introd
uction
Design process
Whats GRASP pattern Whats responsibility
Responsibilities and methods
Responsibilities and InteractionD
iagrams
8/3/2019 GRASP Pattern n
4/17
Design Pro
cess
Design Pro
cess
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.
8/3/2019 GRASP Pattern n
5/17
Whats GRASP pattern
Whats GRASP pattern
This approach to understanding and using
design principles is based on patterns of
assigning responsibilities.
The GRASP patterns are a learning aid to
help one understand essential object design,
and apply design reasoning in a methodical,rational, explainable way.
8/3/2019 GRASP Pattern n
6/17
Whats responsibility
Whats responsibility
Doing:
Doing something itself, such as creating an object or
doing a calculation Initiating action in other objects
Controlling and coordinating activities in other objects.
Knowing:
Knowing about private encapsulated data
Knowing about related objects
Knowing about things it can derive or calculate
8/3/2019 GRASP Pattern n
7/17
Responsibilities and meth
odsResponsibilities and meth
ods
:Sale
:Payment
makePayment create
makePayment implies Sale object has a responsibility to
create a Payment object
8/3/2019 GRASP Pattern n
8/17
Responsibilities andResponsibilities and
Interaction DiagramsInteraction Diagrams Interaction diagrams show choices in
assigning responsibilities to objects.
GRASP patterns guide choices in where to
assign responsibilities.
GRASP patterns are a codification of
widely used basic principles.
8/3/2019 GRASP Pattern n
9/17
Information ExpertInformation Expert
Assign a responsibility to the information expert
the class that has the information necessary to
fulfill the responsibility. What is a general principle of assigning
responsibilities to objects?
Who should be responsible for knowing/doing ?
Domain model (domain expert, domain analysis) to
design model (software classes).
Any existing to any representative.
8/3/2019 GRASP Pattern n
10/17
Example: What information isExample: What information is
needed to determine the grand total?needed to determine the grand total?
Saledate
Product
description
price
itemID
8/3/2019 GRASP Pattern n
11/17
Sale
date
Product
description
price
itemID
SalesLineItem
quantity
Who is information expert?
8/3/2019 GRASP Pattern n
12/17
Sale
date
Product
description
price
itemID
SalesLineItem
quantity
getTotal
getSubTotal
getPrice
8/3/2019 GRASP Pattern n
13/17
Creator
Creator
Who should be responsible for creating a new
instance of some class?
CreationalD
esign Pattern Assign class B the responsibility to create an
instance of class A if one or more of the following
is true:
B aggregates A B contains A
B records instance of A objects
B closely use A objects
B passes initializing data to A
8/3/2019 GRASP Pattern n
14/17
Low
Coupling
Low
Coupling
Coupling is a measure of how strongly one
element is connected to, has knowledge of, or
relies on other elements. Low coupling supports increased reuse.
Our goal is to design for low coupling, so that
changes in one element (sub-system, system,
class, etc.) will limit changes to other elements.
8/3/2019 GRASP Pattern n
15/17
HighC
ohesion
HighC
ohesion
Cohesion is a measure of relatedness.
High Cohesion says elements are strongly related
to one another. Designs with low cohesion are difficult to
maintain and reuse.
One of the fundamental goals of an effective
design is to achieve high cohesion with lowcoupling
8/3/2019 GRASP Pattern n
16/17
Controller
Controller Assign the responsibility for receiving or handling a
system event message to a class representing one of thefollowing choices: Represents the overall system, device, or subsystem
Represents a use case within which the system event occurs. Who should be the controller for system events such as
enterItem and endSale?
Which class should be responsible for receiving system
event message? Interface layer does not handle system events.
The controller receives the service request from the UIlayer and coordinates their fulfillment, ie., Command,Faade, and etc.
8/3/2019 GRASP Pattern n
17/17
Thank You.
Top Related