SlideShare a Scribd company logo
Boutique product development company 
It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
GRASP 
PRINCIPLES 
Boutique product development company 
It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products. 
Raheel Arif | Software Engineer
Understanding responsibilities is key to object-oriented 
design - Martin Fowler 
GRASP 
o GRASP = General Responsibility Assignment Software 
Patterns 
o A set of principles for assigning responsibilities to classes – 
the key skill in OO software design 
Raheel Arif | Software Engineer
GRASP PRINCIPLES 
Raheel Arif | Software Engineer 
9 GRASP principles: 
o Information Expert 
o Creator 
o Low Coupling 
o Controller 
o High Cohesion 
o Polymorphism 
o Pure Fabrication 
o Indirection 
o Protected Variations
GRASP Principles 
Information Expert 
Problem: What is a general principle for assigning 
responsibilities to objects? 
Solution: Assign a responsibility to the information expert, that 
is, the class that has the information necessary to fulfill the 
responsibility. 
Example: E.g., Board information needed to get a Square 
Raheel Arif | Software Engineer
GRASP Principles 
Pros and Cons 
• Facilitates information encapsulation: why? 
o Classes use their own info to fulfill tasks 
• Encourages cohesive, lightweight class definitions 
But: 
• Information expert may contradict patterns of 
Low Coupling and High Cohesion 
Raheel Arif | Software Engineer
GRASP Principles 
Creator 
Problem: Who creates an A? 
Solution: 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 instances of A 
• B closely uses A 
• B has the initializing data for A. 
Raheel Arif | Software Engineer
GRASP Principles 
Who creates the Squares? 
Raheel Arif | Software Engineer
GRASP Principles 
Raheel Arif | Software Engineer
GRASP Principles 
Low Coupling 
Problem: How to support low dependency, low change 
impact, increased reuse? 
Solution: Assign a responsibility so coupling is low. 
Coupling – a measure of how strongly one element is 
connected to, has knowledge of, or relies on other elements 
Raheel Arif | Software Engineer
GRASP Principles 
Low Coupling 
A class with high coupling relies on many other classes – 
leads to problems: 
• Changes in related classes forces local changes 
• Harder to understand in isolation 
• Harder to reuse 
Raheel Arif | Software Engineer
GRASP Principles 
Example 
Raheel Arif | Software Engineer
GRASP Principles 
Benefits 
• Understandability: Classes are easier to understand in 
Raheel Arif | Software Engineer 
isolation 
• Maintainability: Classes aren’t affected by changes in 
other components 
• Reusability: easier to grab hold of classes
GRASP Principles 
Controller 
Problem: Who should be responsible for handling a system 
event? (Or, what object receives and coordinates a system 
operation?) 
Solution: Assign the responsibility for receiving and/or 
handling a system event to one of following choices: 
• Represent the overall system, device or subsystem 
(façade controller) 
• Represent a use case scenario within which the system 
event occurs (a <UseCase>Handler) 
Raheel Arif | Software Engineer
GRASP Principles 
High Cohesion 
Problem: How to keep classes focused and manageable? 
Solution: Assign responsibility so that cohesion remains 
high. 
Cohesion measures how strongly related and focused are 
the responsibilities of an element 
Raheel Arif | Software Engineer
GRASP Principles 
High Cohesion 
Problems from low cohesion (does many unrelated things or 
does too much work): 
• Hard to understand/comprehend 
• Hard to reuse 
• Hard to maintain 
Brittle – easily affected by change 
Raheel Arif | Software Engineer
GRASP Principles 
High Cohesion 
Raheel Arif | Software Engineer
GRASP Principles 
High Cohesion 
• Very low cohesion – a class is responsible for many things 
in different functional areas 
• High cohesion – a class has moderate responsibilities in 
one functional area and collaborates with other classes to 
fulfill tasks 
Raheel Arif | Software Engineer
GRASP Principles 
High Cohesion 
Typically high cohesion => few methods with highly related 
functionality 
Benefits of high cohesion: 
• Easy to maintain 
• Easy to understand 
• Easy to reuse 
Raheel Arif | Software Engineer
GRASP Principles 
Polymorphism 
Problem: How to handle alternatives based on type? 
How to create pluggable software components 
Solution: When related alternatives or behaviors vary by 
type (class), assign responsibilities for the behavior—using 
polymorphic operations—to the 
types for which the behavior varies. 
• Polymorphic operations are those that operate on 
Raheel Arif | Software Engineer 
differing classes 
• Don’t test for the type of the object and use conditional 
logic to perform varying statements based on type.
GRASP Principles 
Monopoly Problem: How to Design for Different Square Actions? 
Raheel Arif | Software Engineer
GRASP Principles 
Polymorphism 
Raheel Arif | Software Engineer
GRASP Principles 
Pure Fabrication 
Problem: What object should have the responsibility, when 
you do not want to violate High Cohesion and Low Coupling, 
or other goals, but solutions offered by Expert (for example) 
are not appropriate? 
Solution: Assign a highly cohesive set of responsibilities to 
an artificial or convenience class that does not represent a 
problem domain concept something made up, to support 
high cohesion, low coupling, and reuse. 
Raheel Arif | Software Engineer
GRASP Principles 
Pure Fabrication- Example 
Who should be responsible for saving Sale instances in a 
relational database? 
- by Information Expert ?? 
- leads to low cohesion 
- and high coupling 
- better: create (“fabricate”) a new class that has this 
Raheel Arif | Software Engineer 
responsibility
GRASP Principles 
Indirection 
Sometimes objects must interact with other objects or external 
systems, which may change (or replaced) in future. Direct coupling to 
such objects or systems may result in modification in our objects 
Problem: Where to assign a responsibility, to avoid direct coupling 
between two (or more) things? How to de-couple objects so that low 
coupling is supported and reuse potential remains higher? 
Solution: 
Assign the responsibility to an intermediate object to mediate 
between other components or services so that they are not directly 
coupled. The intermediary creates an indirection between other 
components. 
Raheel Arif | Software Engineer
GRASP Principles 
Indirection--A Simple Example 
Consider a CreditAuthorizationService class that needs to 
use a Modem 
Bad approach: 
Put low-level calls to the Modem API directly in the methods of the 
CreditAuthorizationClass 
Better approach: 
Add an intermediateModemclass that insulates 
CreditAuthorizationClass from the Modem API. 
Raheel Arif | Software Engineer
GRASP Principles 
Indirection--A Simple Example 
Problems: 
In a Sales System, there are multiple external third-party tax calculators 
that must be supported. 
The system needs to be able to integrate with different calculators 
according to some conditions. 
For example; if total is above 500TL it uses the external "Tax Master" 
program, otherwise "Good As Gold" program. 
Each tax calculator has a different interface . 
One product may support a raw TCP socket protocol, another may offer a 
SOAP interface, and a third may offer a Java RMI interface. 
In the future, a new calculator program may be integrated into the system 
or an existing calculator may be removed 
Actually Sale class is responsible to calculate the total and therefore needs 
the tax. 
However, we want to keep our system (Sale) independent from the varying 
external tax calculators. 
Raheel Arif | Software Engineer
GRASP Principles 
Example: Third-Party (External) Tax Calculators in the NextGen System 
Raheel Arif | Software Engineer
GRASP Principles 
Example: Third-Party (External) Tax Calculators in the NextGen System 
Raheel Arif | Software Engineer
GRASP Principles 
Indirection - Notes 
● The GoF Proxy, Bridge, and Mediator patterns utilize indirection. 
● For that matter, classes created for Indirection are usually also Pure 
Fabrications, thus exemplifying two patterns for the price of one. :-) 
Raheel Arif | Software Engineer 
● Lower coupling between components 
● Indirection is pervasive in computer science: 
"Most problems in computer science can be solved by another 
level of indirection."- David Wheeler 
..but: 
"Most problems in performance can be solved by removing 
another layer of indirection." - anonymous
GRASP Principles 
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. 
(The term "interface" is used in the broadest sense of an access 
view; it does not literally only mean something like a Java interface. 
Raheel Arif | Software Engineer
GRASP Principles 
Protected Variations - Example 
Problem: a client explained that the logistical support application 
used by an airline was a maintenance headache. There was frequent 
modification of the business logic to support the logistics. How do you 
protect the system from variations at this point? 
Raheel Arif | Software Engineer
GRASP Principles 
Protected Variations - Example 
Solution: A rules engine was added to the system, and an external 
rule editor let the subject matter experts update the rules without 
requiring changes to the source code of the system. 
Raheel Arif | Software Engineer
GRASP Principles 
Thank you for your time 
If you have any questions 
then please ask 
Waleed Bin Dawood | Software Engineer

More Related Content

PPTX
PPT
Software cost estimation
PPTX
Odbc and data access objects
PDF
Software engineering a practitioners approach 8th edition pressman solutions ...
PPT
DFD Slides
PPT
Software engineering
PPTX
Cohesion and coupling
PPT
Software cost estimation
Odbc and data access objects
Software engineering a practitioners approach 8th edition pressman solutions ...
DFD Slides
Software engineering
Cohesion and coupling

What's hot (20)

PPT
Unit 3(advanced state modeling & interaction meodelling)
PPTX
PPT
Oracle 10g Introduction 1
PDF
Process Improvement Framework
PPTX
Introduction to distributed database
PPT
Databases: Normalisation
PPTX
MODEL-DRIVEN ENGINEERING (MDE) in Practice
PPTX
Package Diagram
PPT
Uml - An Overview
PPT
Uml in software engineering
PDF
Functional dependency and normalization
PDF
chapter 4-Functional Dependency and Normilization.pdf
PDF
Enhanced Entity-Relationship (EER) Modeling
PPT
REQUIREMENT ENGINEERING
PPTX
Windows form application - C# Training
PPTX
Structured system analysis
PPTX
Data storage and indexing
PPTX
Applications of DBMS(Database Management System)
PPT
11. Storage and File Structure in DBMS
Unit 3(advanced state modeling & interaction meodelling)
Oracle 10g Introduction 1
Process Improvement Framework
Introduction to distributed database
Databases: Normalisation
MODEL-DRIVEN ENGINEERING (MDE) in Practice
Package Diagram
Uml - An Overview
Uml in software engineering
Functional dependency and normalization
chapter 4-Functional Dependency and Normilization.pdf
Enhanced Entity-Relationship (EER) Modeling
REQUIREMENT ENGINEERING
Windows form application - C# Training
Structured system analysis
Data storage and indexing
Applications of DBMS(Database Management System)
11. Storage and File Structure in DBMS
Ad

Similar to GRASP Principles (20)

PPT
GRASP Principles
PPT
PDF
Salesforce Meetup Grasp and Solid in Apex (Speakers: Alexander Popok and Kons...
PPTX
Grasp principles
PPT
Week4 grasp-into
PDF
Grasp oose week 14.pdf
PDF
GRASP - one more way to reach clean code
PDF
Responsibility Driven Design
PPTX
C:\Fakepath\Combating Software Entropy 2
PPTX
C:\Fakepath\Combating Software Entropy 2
PPTX
Patterns of Assigning Responsibilities
PDF
Useful Design Patterns for Enterprise Applications with Java
PPTX
SOLID Principles of Refactoring Presentation - Inland Empire User Group
PPTX
Grasp patterns and its types
PDF
CS8592-OOAD Lecture Notes Unit-4
PPTX
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
PDF
Software design principles - jinal desai
PPT
Writing Quality Code
GRASP Principles
Salesforce Meetup Grasp and Solid in Apex (Speakers: Alexander Popok and Kons...
Grasp principles
Week4 grasp-into
Grasp oose week 14.pdf
GRASP - one more way to reach clean code
Responsibility Driven Design
C:\Fakepath\Combating Software Entropy 2
C:\Fakepath\Combating Software Entropy 2
Patterns of Assigning Responsibilities
Useful Design Patterns for Enterprise Applications with Java
SOLID Principles of Refactoring Presentation - Inland Empire User Group
Grasp patterns and its types
CS8592-OOAD Lecture Notes Unit-4
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software design principles - jinal desai
Writing Quality Code
Ad

Recently uploaded (20)

PPTX
ai tools demonstartion for schools and inter college
PPTX
Introduction to Artificial Intelligence
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administration Chapter 2
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
medical staffing services at VALiNTRY
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
top salesforce developer skills in 2025.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Nekopoi APK 2025 free lastest update
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college
Introduction to Artificial Intelligence
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Operating system designcfffgfgggggggvggggggggg
System and Network Administration Chapter 2
Odoo Companies in India – Driving Business Transformation.pdf
Digital Strategies for Manufacturing Companies
medical staffing services at VALiNTRY
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms I-SECS-1021-03
How to Choose the Right IT Partner for Your Business in Malaysia
CHAPTER 2 - PM Management and IT Context
top salesforce developer skills in 2025.pdf
Online Work Permit System for Fast Permit Processing
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Nekopoi APK 2025 free lastest update
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Design an Analysis of Algorithms II-SECS-1021-03
2025 Textile ERP Trends: SAP, Odoo & Oracle

GRASP Principles

  • 1. Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
  • 2. GRASP PRINCIPLES Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products. Raheel Arif | Software Engineer
  • 3. Understanding responsibilities is key to object-oriented design - Martin Fowler GRASP o GRASP = General Responsibility Assignment Software Patterns o A set of principles for assigning responsibilities to classes – the key skill in OO software design Raheel Arif | Software Engineer
  • 4. GRASP PRINCIPLES Raheel Arif | Software Engineer 9 GRASP principles: o Information Expert o Creator o Low Coupling o Controller o High Cohesion o Polymorphism o Pure Fabrication o Indirection o Protected Variations
  • 5. GRASP Principles Information Expert Problem: What is a general principle for assigning responsibilities to objects? Solution: Assign a responsibility to the information expert, that is, the class that has the information necessary to fulfill the responsibility. Example: E.g., Board information needed to get a Square Raheel Arif | Software Engineer
  • 6. GRASP Principles Pros and Cons • Facilitates information encapsulation: why? o Classes use their own info to fulfill tasks • Encourages cohesive, lightweight class definitions But: • Information expert may contradict patterns of Low Coupling and High Cohesion Raheel Arif | Software Engineer
  • 7. GRASP Principles Creator Problem: Who creates an A? Solution: 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 instances of A • B closely uses A • B has the initializing data for A. Raheel Arif | Software Engineer
  • 8. GRASP Principles Who creates the Squares? Raheel Arif | Software Engineer
  • 9. GRASP Principles Raheel Arif | Software Engineer
  • 10. GRASP Principles Low Coupling Problem: How to support low dependency, low change impact, increased reuse? Solution: Assign a responsibility so coupling is low. Coupling – a measure of how strongly one element is connected to, has knowledge of, or relies on other elements Raheel Arif | Software Engineer
  • 11. GRASP Principles Low Coupling A class with high coupling relies on many other classes – leads to problems: • Changes in related classes forces local changes • Harder to understand in isolation • Harder to reuse Raheel Arif | Software Engineer
  • 12. GRASP Principles Example Raheel Arif | Software Engineer
  • 13. GRASP Principles Benefits • Understandability: Classes are easier to understand in Raheel Arif | Software Engineer isolation • Maintainability: Classes aren’t affected by changes in other components • Reusability: easier to grab hold of classes
  • 14. GRASP Principles Controller Problem: Who should be responsible for handling a system event? (Or, what object receives and coordinates a system operation?) Solution: Assign the responsibility for receiving and/or handling a system event to one of following choices: • Represent the overall system, device or subsystem (façade controller) • Represent a use case scenario within which the system event occurs (a <UseCase>Handler) Raheel Arif | Software Engineer
  • 15. GRASP Principles High Cohesion Problem: How to keep classes focused and manageable? Solution: Assign responsibility so that cohesion remains high. Cohesion measures how strongly related and focused are the responsibilities of an element Raheel Arif | Software Engineer
  • 16. GRASP Principles High Cohesion Problems from low cohesion (does many unrelated things or does too much work): • Hard to understand/comprehend • Hard to reuse • Hard to maintain Brittle – easily affected by change Raheel Arif | Software Engineer
  • 17. GRASP Principles High Cohesion Raheel Arif | Software Engineer
  • 18. GRASP Principles High Cohesion • Very low cohesion – a class is responsible for many things in different functional areas • High cohesion – a class has moderate responsibilities in one functional area and collaborates with other classes to fulfill tasks Raheel Arif | Software Engineer
  • 19. GRASP Principles High Cohesion Typically high cohesion => few methods with highly related functionality Benefits of high cohesion: • Easy to maintain • Easy to understand • Easy to reuse Raheel Arif | Software Engineer
  • 20. GRASP Principles Polymorphism Problem: How to handle alternatives based on type? How to create pluggable software components Solution: When related alternatives or behaviors vary by type (class), assign responsibilities for the behavior—using polymorphic operations—to the types for which the behavior varies. • Polymorphic operations are those that operate on Raheel Arif | Software Engineer differing classes • Don’t test for the type of the object and use conditional logic to perform varying statements based on type.
  • 21. GRASP Principles Monopoly Problem: How to Design for Different Square Actions? Raheel Arif | Software Engineer
  • 22. GRASP Principles Polymorphism Raheel Arif | Software Engineer
  • 23. GRASP Principles Pure Fabrication Problem: What object should have the responsibility, when you do not want to violate High Cohesion and Low Coupling, or other goals, but solutions offered by Expert (for example) are not appropriate? Solution: Assign a highly cohesive set of responsibilities to an artificial or convenience class that does not represent a problem domain concept something made up, to support high cohesion, low coupling, and reuse. Raheel Arif | Software Engineer
  • 24. GRASP Principles Pure Fabrication- Example Who should be responsible for saving Sale instances in a relational database? - by Information Expert ?? - leads to low cohesion - and high coupling - better: create (“fabricate”) a new class that has this Raheel Arif | Software Engineer responsibility
  • 25. GRASP Principles Indirection Sometimes objects must interact with other objects or external systems, which may change (or replaced) in future. Direct coupling to such objects or systems may result in modification in our objects Problem: Where to assign a responsibility, to avoid direct coupling between two (or more) things? How to de-couple objects so that low coupling is supported and reuse potential remains higher? Solution: Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. The intermediary creates an indirection between other components. Raheel Arif | Software Engineer
  • 26. GRASP Principles Indirection--A Simple Example Consider a CreditAuthorizationService class that needs to use a Modem Bad approach: Put low-level calls to the Modem API directly in the methods of the CreditAuthorizationClass Better approach: Add an intermediateModemclass that insulates CreditAuthorizationClass from the Modem API. Raheel Arif | Software Engineer
  • 27. GRASP Principles Indirection--A Simple Example Problems: In a Sales System, there are multiple external third-party tax calculators that must be supported. The system needs to be able to integrate with different calculators according to some conditions. For example; if total is above 500TL it uses the external "Tax Master" program, otherwise "Good As Gold" program. Each tax calculator has a different interface . One product may support a raw TCP socket protocol, another may offer a SOAP interface, and a third may offer a Java RMI interface. In the future, a new calculator program may be integrated into the system or an existing calculator may be removed Actually Sale class is responsible to calculate the total and therefore needs the tax. However, we want to keep our system (Sale) independent from the varying external tax calculators. Raheel Arif | Software Engineer
  • 28. GRASP Principles Example: Third-Party (External) Tax Calculators in the NextGen System Raheel Arif | Software Engineer
  • 29. GRASP Principles Example: Third-Party (External) Tax Calculators in the NextGen System Raheel Arif | Software Engineer
  • 30. GRASP Principles Indirection - Notes ● The GoF Proxy, Bridge, and Mediator patterns utilize indirection. ● For that matter, classes created for Indirection are usually also Pure Fabrications, thus exemplifying two patterns for the price of one. :-) Raheel Arif | Software Engineer ● Lower coupling between components ● Indirection is pervasive in computer science: "Most problems in computer science can be solved by another level of indirection."- David Wheeler ..but: "Most problems in performance can be solved by removing another layer of indirection." - anonymous
  • 31. GRASP Principles 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. (The term "interface" is used in the broadest sense of an access view; it does not literally only mean something like a Java interface. Raheel Arif | Software Engineer
  • 32. GRASP Principles Protected Variations - Example Problem: a client explained that the logistical support application used by an airline was a maintenance headache. There was frequent modification of the business logic to support the logistics. How do you protect the system from variations at this point? Raheel Arif | Software Engineer
  • 33. GRASP Principles Protected Variations - Example Solution: A rules engine was added to the system, and an external rule editor let the subject matter experts update the rules without requiring changes to the source code of the system. Raheel Arif | Software Engineer
  • 34. GRASP Principles Thank you for your time If you have any questions then please ask Waleed Bin Dawood | Software Engineer