SlideShare ist ein Scribd-Unternehmen logo
1 von 34
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

Weitere ähnliche Inhalte

Was ist angesagt?

Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
Haitham El-Ghareeb
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
soms_1
 
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use cases
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use casesModel-driven Software Engineering in practice: Chapter 3 - MDSE Use cases
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use cases
Jordi Cabot
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - Adapter
Manoj Kumar
 

Was ist angesagt? (20)

Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Introduction to MDA
Introduction to MDAIntroduction to MDA
Introduction to MDA
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Service Oriented Computing - Session1 : Intro
Service Oriented Computing - Session1 : IntroService Oriented Computing - Session1 : Intro
Service Oriented Computing - Session1 : Intro
 
Spm unit1
Spm unit1Spm unit1
Spm unit1
 
09 grasp
09 grasp09 grasp
09 grasp
 
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use cases
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use casesModel-driven Software Engineering in practice: Chapter 3 - MDSE Use cases
Model-driven Software Engineering in practice: Chapter 3 - MDSE Use cases
 
Domain object model
Domain object modelDomain object model
Domain object model
 
1. introduction to uml
1. introduction to uml1. introduction to uml
1. introduction to uml
 
UML Architecture and Views
UML Architecture and ViewsUML Architecture and Views
UML Architecture and Views
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Grasp principles
Grasp principlesGrasp principles
Grasp principles
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - Adapter
 
Programación Orientada por Objetos para programadores Ruby
Programación Orientada por Objetos para programadores RubyProgramación Orientada por Objetos para programadores Ruby
Programación Orientada por Objetos para programadores Ruby
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Design patterns in PHP
Design patterns in PHPDesign patterns in PHP
Design patterns in PHP
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Builder design pattern
Builder design patternBuilder design pattern
Builder design pattern
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 

Ähnlich wie GRASP Principles

Introduction to DevOps slides-converted (1).pptx
Introduction to DevOps slides-converted (1).pptxIntroduction to DevOps slides-converted (1).pptx
Introduction to DevOps slides-converted (1).pptx
aasssss1
 
Sfeldman performance bb_worldemea07
Sfeldman performance bb_worldemea07Sfeldman performance bb_worldemea07
Sfeldman performance bb_worldemea07
Steve Feldman
 
Assess enterprise applications for cloud migration
Assess enterprise applications for cloud migrationAssess enterprise applications for cloud migration
Assess enterprise applications for cloud migration
nanda1505
 
Timeline Consulting_Where Next For ERP
Timeline Consulting_Where Next For ERPTimeline Consulting_Where Next For ERP
Timeline Consulting_Where Next For ERP
Jim Foster
 
Online student management system
Online student management systemOnline student management system
Online student management system
Mumbai Academisc
 
Different Methodologies Used By Programming Teams
Different Methodologies Used By Programming TeamsDifferent Methodologies Used By Programming Teams
Different Methodologies Used By Programming Teams
Nicole Gomez
 
Four principles seminar manageware seminar
Four principles seminar   manageware seminarFour principles seminar   manageware seminar
Four principles seminar manageware seminar
Manageware
 

Ähnlich wie GRASP Principles (20)

Software process model
Software process modelSoftware process model
Software process model
 
Chapter 3 Software Process Model.ppt
Chapter 3 Software Process Model.pptChapter 3 Software Process Model.ppt
Chapter 3 Software Process Model.ppt
 
Introduction to DevOps slides-converted (1).pptx
Introduction to DevOps slides-converted (1).pptxIntroduction to DevOps slides-converted (1).pptx
Introduction to DevOps slides-converted (1).pptx
 
Sfeldman performance bb_worldemea07
Sfeldman performance bb_worldemea07Sfeldman performance bb_worldemea07
Sfeldman performance bb_worldemea07
 
Software Process Model in software engineering
Software Process Model in software engineeringSoftware Process Model in software engineering
Software Process Model in software engineering
 
Assess enterprise applications for cloud migration
Assess enterprise applications for cloud migrationAssess enterprise applications for cloud migration
Assess enterprise applications for cloud migration
 
Top trends in erp 2017v8.compressed
Top trends in erp 2017v8.compressedTop trends in erp 2017v8.compressed
Top trends in erp 2017v8.compressed
 
Timeline Consulting_Where Next For ERP
Timeline Consulting_Where Next For ERPTimeline Consulting_Where Next For ERP
Timeline Consulting_Where Next For ERP
 
Online student management system
Online student management systemOnline student management system
Online student management system
 
RUP
RUPRUP
RUP
 
Maximize your Oracle Cloud Investment and Drive Innovation
 Maximize your Oracle Cloud Investment and Drive Innovation Maximize your Oracle Cloud Investment and Drive Innovation
Maximize your Oracle Cloud Investment and Drive Innovation
 
IBM Cloud Service Management and Operations Field Guide
IBM Cloud Service Management and Operations Field GuideIBM Cloud Service Management and Operations Field Guide
IBM Cloud Service Management and Operations Field Guide
 
Enterprise Agile at Lockheed Martin - 4th February 2014
Enterprise Agile at Lockheed Martin - 4th February 2014Enterprise Agile at Lockheed Martin - 4th February 2014
Enterprise Agile at Lockheed Martin - 4th February 2014
 
Different Methodologies Used By Programming Teams
Different Methodologies Used By Programming TeamsDifferent Methodologies Used By Programming Teams
Different Methodologies Used By Programming Teams
 
Automation, Audits, and Apps Tour
Automation, Audits, and Apps TourAutomation, Audits, and Apps Tour
Automation, Audits, and Apps Tour
 
9 Principles for Salesforce Application Architecture
9 Principles for Salesforce Application Architecture9 Principles for Salesforce Application Architecture
9 Principles for Salesforce Application Architecture
 
Four principles seminar manageware seminar
Four principles seminar   manageware seminarFour principles seminar   manageware seminar
Four principles seminar manageware seminar
 
David Leslie - Testing at MACH Speed.pptx
David Leslie - Testing at MACH Speed.pptxDavid Leslie - Testing at MACH Speed.pptx
David Leslie - Testing at MACH Speed.pptx
 
Introduction to ERP Concept
Introduction to ERP ConceptIntroduction to ERP Concept
Introduction to ERP Concept
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 

Kürzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 

Kürzlich hochgeladen (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

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