Submitted To: 
Submitted by: 
Fizza Durrani 
11073 
7th Semester UET(A) 
October 15, 2014 
Lahore Garrison University 1
“The critical design tool for software 
development is a mind well educated in 
design principles. It is not the UML or any 
other technology.“ 
Craig Larman 
Thus, GRASP is really a mental toolset, a learning 
aid to help in the design of object-oriented 
software. 
Lahore Garrison University 2
It stands for: 
 General 
 Responsibilities 
 Assignment 
 Software 
 Patterns (Principles) 
Lahore Garrison University 3
Responsibility 
A contract / obligation that a class / module / 
component must accomplish 
 Knowledge 
 Private state 
 Computed state 
 
 
 Behavior 
 Send messages itself and modify its private 
state 
 Instantiate another objects 
 Send messages to another objects 
Lahore Garrison University 4
 “doing” responsibilities 
 Doing something itself, such as creation an 
object or doing a calculation. 
 Initiating action in other objects 
 Controlling and coordinating activities in other 
objects. 
 “knowing” responsibilities 
 Knowing about encapsulated data. 
 Knowing about related objects. 
 Knowing about things it can derive or 
calculate. 
Lahore Garrison University 5
Lahore Garrison University 6
 Informational Expert 
 Creator 
 Low Coupling 
 High Cohesion 
 Controller 
 Polymorphism 
 Pure Fabrication 
 Indirection 
 Controlled Variation 
Lahore Garrison University 7
Lahore Garrison University 8
Problem: Which class possesses information 
about object A? 
More common question: What is a general 
principle of assigning responsibilities to 
objects? 
Assign the responsibility to the class that 
knows the necessary information for 
performing required action and fulfill the 
responsibility. 
Lahore Garrison University 9
A B C D 
DO 
GetDataX() 
GetDataY() 
GetDataZ() 
return Z 
return Y 
return X 
Lahore Garrison University 10
A B C D 
DO 
DoAction() 
DoAction(X) 
DoAction(Y) 
Lahore Garrison University 11
Lahore Garrison University 12
Problem: Who should be responsible for creating 
object 
A? 
 Class B must have that responsibility if: 
 B is composed by A (composition) 
 B knows the necessary information in order to 
instantiate A objects 
 B depends heavily on A 
Lahore Garrison University 13
• The goal is to define creator-object, which will be 
related to all created objects. 
64 
Board Square 
Square 
Board 
create 
create 
Lahore Garrison University 14
Lahore Garrison University 15
Problem: How to minimize dependencies between 
classes ? 
Coupling is the degree, defines how tightly one 
component linked to other components, or how 
much 
information it knows about other components. 
Examples 
 Inheritance 
 Composition / aggregation / association 
 A send messages to B 
Lahore Garrison University 16
 Assign a responsibility so that coupling remains 
low. 
Low Coupling is an evaluative pattern, which 
dictates how to assign responsibilities to support: 
 lower dependency between the classes, 
 change in one class having lower impact on 
other classes, 
 higher reuse potential. 
Lahore Garrison University 17
Lahore Garrison University 18
Problem: How to keep objects focused, 
understandable, manageable, and support low 
coupling? 
Cohesion is a measure of how strongly related 
or focused the responsibilities of a single module 
are. 
High Cohesion is an evaluative pattern that 
attempts to keep objects appropriately focused, 
manageable and understandable. 
Lahore Garrison University 19
 Alternatively, low cohesion is a situation in 
which a given element has too many unrelated 
responsibilities (“God Object”) 
Low Cohesion implies: 
 Hard to reuse 
 Hard to maintain 
 Constantly changing 
Lahore Garrison University 20
A A ?? ?? 
DoA() 
DoB() 
DoC() 
DoA() 
DoB() 
DoC() 
Lahore Garrison University 21
Lahore Garrison University 22
Problem: Who should be responsible for 
handling events and messages from external 
actors (UI, …)? 
 Assign the responsibility to a class, such as: 
A class that represents the overall system, 
device, or subsystem. 
Façade Controller Pattern 
A class that represent a use case, whereby 
performs handling particular system operation. 
Use Case Controller Pattern 
 Generally does not perform operation by itself, but delegate 
responsibility to component objects. 
Lahore Garrison University 23
Lahore Garrison University 24
Problem: How to act different depending in 
object’s 
class, or how to design pluggable components? 
 In case of class behavior might changes, 
responsibilities segregates to different behavior 
specific classes, using polymorphic operations 
for this class. 
 Advise: Do not use type checking, but 
conditional logic for implementation different 
variations based on object type. 
Lahore Garrison University 25
Player 
 There are (roughly) 3 types a polymorphism: 
 Ad hoc Polymorphism 
 Parametric Polymorphism 
 Subtype Polymorphism 
Square 
landedOn 
RegularSquare 
landedOn 
GoSquare 
landedOn 
OtherSquare 
landedOn 
Lahore Garrison University 26
Lahore Garrison University 27
 Problem: How to assign responsibilities if applying the 
Informational Expert principle decreases cohesion and 
increases coupling? 
 Assign the responsibility to an artificial class that does 
not belongs to the domain model. 
 Pure Fabrication is a class that does not reflect any 
business domain object, but required only for increase 
cohesion and decrease coupling. 
Lahore Garrison University 28
Lahore Garrison University 29
 Problem: How to assign responsibilities in order to avoid 
direct coupling between two components, and keep 
ability for reuse. 
 Assign responsibility to intermediate class for providing 
linking between objects not linking directly. 
 Related design patterns: Adapter, Bridge, Mediator. 
Lahore Garrison University 30
Lahore Garrison University 31
 Problem: How to design system and subsystems, 
that changes in these components does not affects 
on other components. 
 Identify points of possible variations and instability; 
create stable interfaces upon instable components. 
Open-Closed Principle almost equivalent to CV 
pattern. 
Lahore Garrison University 32
 There are 2 types of points: 
 Variation point – branching point on existing system or 
in requirements. For example we need to support 
several types of interfaces for tax payment system 
 Evolution point – supposed branching point, which 
might occur in future, but does not declared by existing 
requirements. 
 Protected variation pattern applying for both variation 
and evolution points. 
Lahore Garrison University 33
Informational Expert Assign a responsibility to the class that has the 
information needed to fulfill it. 
Creator Assign class B the responsibility to create an instance 
of class A if one of these is true (the more the better): 
• B "contains" or compositely aggregates A. 
• B records A. 
• B closely uses A. 
• B has the initializing data for A that will be passed 
to A when it is crated. Thus B is an Expert with 
respect to creating A. 
Controller Assign the responsibility to a class representing one 
of the following choices: 
• Major subsystem classes 
• A use case scenario classes within which the 
system event occurs 
Low Coupling Assign a responsibility so that coupling remains low. 
High Cohesion Lahore GarArissons Uingivners iaty responsibility so that coh3e4 sion remains high.
Polymorphism The same name operations (methods) in the 
difference classes is defined. And assign a 
responsibility to the class the class that the behavior 
is changed. 
Pure Fabrication Define a class for convenience' sake that doesn't 
express the concept of the problem area at all. 
Indirection Assign the responsibility to an intermediate object to 
mediate between other components or services, so 
that they are not directly coupled. 
Protected Variations Assign responsibility to create a stable interface 
around an unstable or predictably variable subsystem 
or component. 
Lahore Garrison University 35
 http://en.wikipedia.org/wiki/GRASP_%28object-oriented_ 
design%29 
 http://www.slideshare.net/snmgian/grasp-principles 
 http://www.slideshare.net/eduardo_diederichsen/d 
esign-talk-grasp-patterns?related=1 
 http://www.slideshare.net/eduardo_diederichsen/d 
esign-talk-grasp-patterns?related=1 
Lahore Garrison University 36
Any Question 
Lahore Garrison University 37
Lahore Garrison University 38

Grasp

  • 1.
    Submitted To: Submittedby: Fizza Durrani 11073 7th Semester UET(A) October 15, 2014 Lahore Garrison University 1
  • 2.
    “The critical designtool for software development is a mind well educated in design principles. It is not the UML or any other technology.“ Craig Larman Thus, GRASP is really a mental toolset, a learning aid to help in the design of object-oriented software. Lahore Garrison University 2
  • 3.
    It stands for:  General  Responsibilities  Assignment  Software  Patterns (Principles) Lahore Garrison University 3
  • 4.
    Responsibility A contract/ obligation that a class / module / component must accomplish  Knowledge  Private state  Computed state    Behavior  Send messages itself and modify its private state  Instantiate another objects  Send messages to another objects Lahore Garrison University 4
  • 5.
     “doing” responsibilities  Doing something itself, such as creation an object or doing a calculation.  Initiating action in other objects  Controlling and coordinating activities in other objects.  “knowing” responsibilities  Knowing about encapsulated data.  Knowing about related objects.  Knowing about things it can derive or calculate. Lahore Garrison University 5
  • 6.
  • 7.
     Informational Expert  Creator  Low Coupling  High Cohesion  Controller  Polymorphism  Pure Fabrication  Indirection  Controlled Variation Lahore Garrison University 7
  • 8.
  • 9.
    Problem: Which classpossesses information about object A? More common question: What is a general principle of assigning responsibilities to objects? Assign the responsibility to the class that knows the necessary information for performing required action and fulfill the responsibility. Lahore Garrison University 9
  • 10.
    A B CD DO GetDataX() GetDataY() GetDataZ() return Z return Y return X Lahore Garrison University 10
  • 11.
    A B CD DO DoAction() DoAction(X) DoAction(Y) Lahore Garrison University 11
  • 12.
  • 13.
    Problem: Who shouldbe responsible for creating object A?  Class B must have that responsibility if:  B is composed by A (composition)  B knows the necessary information in order to instantiate A objects  B depends heavily on A Lahore Garrison University 13
  • 14.
    • The goalis to define creator-object, which will be related to all created objects. 64 Board Square Square Board create create Lahore Garrison University 14
  • 15.
  • 16.
    Problem: How tominimize dependencies between classes ? Coupling is the degree, defines how tightly one component linked to other components, or how much information it knows about other components. Examples  Inheritance  Composition / aggregation / association  A send messages to B Lahore Garrison University 16
  • 17.
     Assign aresponsibility so that coupling remains low. Low Coupling is an evaluative pattern, which dictates how to assign responsibilities to support:  lower dependency between the classes,  change in one class having lower impact on other classes,  higher reuse potential. Lahore Garrison University 17
  • 18.
  • 19.
    Problem: How tokeep objects focused, understandable, manageable, and support low coupling? Cohesion is a measure of how strongly related or focused the responsibilities of a single module are. High Cohesion is an evaluative pattern that attempts to keep objects appropriately focused, manageable and understandable. Lahore Garrison University 19
  • 20.
     Alternatively, lowcohesion is a situation in which a given element has too many unrelated responsibilities (“God Object”) Low Cohesion implies:  Hard to reuse  Hard to maintain  Constantly changing Lahore Garrison University 20
  • 21.
    A A ???? DoA() DoB() DoC() DoA() DoB() DoC() Lahore Garrison University 21
  • 22.
  • 23.
    Problem: Who shouldbe responsible for handling events and messages from external actors (UI, …)?  Assign the responsibility to a class, such as: A class that represents the overall system, device, or subsystem. Façade Controller Pattern A class that represent a use case, whereby performs handling particular system operation. Use Case Controller Pattern  Generally does not perform operation by itself, but delegate responsibility to component objects. Lahore Garrison University 23
  • 24.
  • 25.
    Problem: How toact different depending in object’s class, or how to design pluggable components?  In case of class behavior might changes, responsibilities segregates to different behavior specific classes, using polymorphic operations for this class.  Advise: Do not use type checking, but conditional logic for implementation different variations based on object type. Lahore Garrison University 25
  • 26.
    Player  Thereare (roughly) 3 types a polymorphism:  Ad hoc Polymorphism  Parametric Polymorphism  Subtype Polymorphism Square landedOn RegularSquare landedOn GoSquare landedOn OtherSquare landedOn Lahore Garrison University 26
  • 27.
  • 28.
     Problem: Howto assign responsibilities if applying the Informational Expert principle decreases cohesion and increases coupling?  Assign the responsibility to an artificial class that does not belongs to the domain model.  Pure Fabrication is a class that does not reflect any business domain object, but required only for increase cohesion and decrease coupling. Lahore Garrison University 28
  • 29.
  • 30.
     Problem: Howto assign responsibilities in order to avoid direct coupling between two components, and keep ability for reuse.  Assign responsibility to intermediate class for providing linking between objects not linking directly.  Related design patterns: Adapter, Bridge, Mediator. Lahore Garrison University 30
  • 31.
  • 32.
     Problem: Howto design system and subsystems, that changes in these components does not affects on other components.  Identify points of possible variations and instability; create stable interfaces upon instable components. Open-Closed Principle almost equivalent to CV pattern. Lahore Garrison University 32
  • 33.
     There are2 types of points:  Variation point – branching point on existing system or in requirements. For example we need to support several types of interfaces for tax payment system  Evolution point – supposed branching point, which might occur in future, but does not declared by existing requirements.  Protected variation pattern applying for both variation and evolution points. Lahore Garrison University 33
  • 34.
    Informational Expert Assigna responsibility to the class that has the information needed to fulfill it. Creator Assign class B the responsibility to create an instance of class A if one of these is true (the more the better): • B "contains" or compositely aggregates A. • B records A. • B closely uses A. • B has the initializing data for A that will be passed to A when it is crated. Thus B is an Expert with respect to creating A. Controller Assign the responsibility to a class representing one of the following choices: • Major subsystem classes • A use case scenario classes within which the system event occurs Low Coupling Assign a responsibility so that coupling remains low. High Cohesion Lahore GarArissons Uingivners iaty responsibility so that coh3e4 sion remains high.
  • 35.
    Polymorphism The samename operations (methods) in the difference classes is defined. And assign a responsibility to the class the class that the behavior is changed. Pure Fabrication Define a class for convenience' sake that doesn't express the concept of the problem area at all. Indirection Assign the responsibility to an intermediate object to mediate between other components or services, so that they are not directly coupled. Protected Variations Assign responsibility to create a stable interface around an unstable or predictably variable subsystem or component. Lahore Garrison University 35
  • 36.
     http://en.wikipedia.org/wiki/GRASP_%28object-oriented_ design%29  http://www.slideshare.net/snmgian/grasp-principles  http://www.slideshare.net/eduardo_diederichsen/d esign-talk-grasp-patterns?related=1  http://www.slideshare.net/eduardo_diederichsen/d esign-talk-grasp-patterns?related=1 Lahore Garrison University 36
  • 37.
    Any Question LahoreGarrison University 37
  • 38.