SlideShare una empresa de Scribd logo
1 de 26
GRASP: Designing ObjectsGRASP: Designing Objects
with Responsibilitieswith Responsibilities
Applying UML and PatternsApplying UML and Patterns
Craig LarmanCraig Larman
Chapter 17Chapter 17
Glenn D. Blank CSE432, Lehigh UniversityGlenn D. Blank CSE432, Lehigh University
Chapter Learning ObjectivesChapter Learning Objectives
 Learn about design patternsLearn about design patterns
 Learn how to apply five GRASP patternsLearn how to apply five GRASP patterns
 You’ve learned about static class diagramsYou’ve learned about static class diagrams
and dynamic interaction diagramsand dynamic interaction diagrams
 UML is just notation; now you need to learnUML is just notation; now you need to learn
how to make effective use of the notationhow to make effective use of the notation
 UML modeling is an art, guided by principlesUML modeling is an art, guided by principles
Design patterns in architectureDesign patterns in architecture
 AA patternpattern is ais a recurringrecurring solutionsolution to a standardto a standard problemproblem,,
in ain a contextcontext..
 Christopher Alexander, professor of architecture…Christopher Alexander, professor of architecture…
– Why is what a prof of architectureWhy is what a prof of architecture
says relevant to software?says relevant to software?
– ““A pattern describes a problemA pattern describes a problem
which occurs over and over againwhich occurs over and over again
in our environment, and thenin our environment, and then
describes the core of the solutiondescribes the core of the solution
to that problem, in such a way thatto that problem, in such a way that
you can use this solution a millionyou can use this solution a million
times over, without ever doing ittimes over, without ever doing it
the same way twice.”the same way twice.”
Design and dress patternsDesign and dress patterns
 Jim Coplein, a software engineer:Jim Coplein, a software engineer:
““I like to relate this definition to dress patterns …I like to relate this definition to dress patterns …
I could tell you how toI could tell you how to
make a dress by specifyingmake a dress by specifying
the route of a scissorsthe route of a scissors
through a piece of cloththrough a piece of cloth
in terms of angles andin terms of angles and
lengths of cut. Or, I couldlengths of cut. Or, I could
give you a pattern.give you a pattern.
Reading the specification,Reading the specification,
you would have no ideayou would have no idea
what was being built or if you had built the right thing whenwhat was being built or if you had built the right thing when
you were finished. The pattern foreshadows the product:you were finished. The pattern foreshadows the product:
it is the rule for making the thing, but it is also,it is the rule for making the thing, but it is also,
in many respects, the thing itself.”in many respects, the thing itself.”
Patterns in engineeringPatterns in engineering
 How do other engineers find and use patterns?How do other engineers find and use patterns?
– Mature engineering disciplines haveMature engineering disciplines have handbookshandbooks
describing successful solutions to known problemsdescribing successful solutions to known problems
– Automobile designers don't design cars from scratchAutomobile designers don't design cars from scratch
using the laws of physicsusing the laws of physics
– Instead, theyInstead, they reusereuse standard designs with successfulstandard designs with successful
track records, learning from experiencetrack records, learning from experience
– Should software engineers make use of patterns?Should software engineers make use of patterns?
Why?Why?
– ““Be sure that you make everything according to the patternBe sure that you make everything according to the pattern
I have shown you here on the mountain.” Exodus 25:40.I have shown you here on the mountain.” Exodus 25:40.
 Developing software from scratch is also expensiveDeveloping software from scratch is also expensive
– Patterns supportPatterns support reusereuse of software architecture designof software architecture design
Definitions and namesDefinitions and names
 Alexander: “AAlexander: “A patternpattern is ais a recurringrecurring solutionsolution
to a standardto a standard problemproblem, in a, in a contextcontext.”.”
 Larman: “In OO design, aLarman: “In OO design, a patternpattern is a namedis a named
description of a problem and solution that can bedescription of a problem and solution that can be
applied in new contexts; ideally,applied in new contexts; ideally,
a pattern advises us on how to apply the solutiona pattern advises us on how to apply the solution
in varying circumstances and considersin varying circumstances and considers
the forces and trade-offs.”the forces and trade-offs.”
 How is Larman’s definition similar to Alexander’s?How is Larman’s definition similar to Alexander’s?
 How are these definitions significantly different?How are these definitions significantly different?
 Patterns have suggestive names:Patterns have suggestive names:
– Arched Columns Pattern, Easy Toddler Dress Pattern,Arched Columns Pattern, Easy Toddler Dress Pattern,
etc.etc.
 Why is naming a pattern or principle helpful?Why is naming a pattern or principle helpful?
– It supports chunking and incorporating that conceptIt supports chunking and incorporating that concept
into our understanding and memoryinto our understanding and memory
– It facilitates communicationIt facilitates communication
Naming Patterns—important!Naming Patterns—important!
Star and Plume Quilt
GRASPGRASP
 Name chosen to suggest the importance ofName chosen to suggest the importance of
graspgrasping fundamental principles to successfullying fundamental principles to successfully
design object-oriented softwaredesign object-oriented software
 Acronym forAcronym for GGeneraleneral RResponsibilityesponsibility
AAssignmentssignment SSoftwareoftware PPatternsatterns
 Describe fundamental principles ofDescribe fundamental principles of
object design and responsibilityobject design and responsibility
 Expressed as patternsExpressed as patterns
Five GRASP patterns:Five GRASP patterns:
 CreatorCreator
 Information ExpertInformation Expert
 Low CouplingLow Coupling
 ControllerController
 High CohesionHigh Cohesion
Creator patternCreator pattern
Name:Name: CreatorCreator
Problem: Who creates an instance of A?Problem: Who creates an instance of A?
Solution: Assign class B the responsibilitySolution: Assign class B the responsibility
to create an instance of class A if one ofto create an instance of class A if one of
these is true (the more the better):these is true (the more the better):
 B contains or aggregates A (in a collection)B contains or aggregates A (in a collection)
 B records AB records A
 B closely uses AB closely uses A
 B has the initializing data for AB has the initializing data for A
Who creates the Squares?Who creates the Squares?
Figure 17.3, page 283Figure 17.3, page 283
How does Create pattern lead toHow does Create pattern lead to
this partial Sequence diagram?this partial Sequence diagram?
Figure 17.4, page 283Figure 17.4, page 283
How does Create pattern developHow does Create pattern develop
this Design Class Diagram (DCD)?this Design Class Diagram (DCD)?
Figure 17.5 , page 283Figure 17.5 , page 283
Board has a composite aggregation relationship with Square
• I.e., Board contains a collection of Squares
Discussion of Creator patternDiscussion of Creator pattern
 Responsibilities for object creation are commonResponsibilities for object creation are common
 Connect an object to its creator when:Connect an object to its creator when:
– Aggregator aggregates PartAggregator aggregates Part
– Container contains ContentContainer contains Content
– Recorder recordsRecorder records
– Initializing data passed in during creationInitializing data passed in during creation
Contraindications or caveatsContraindications or caveats
 Creation may require significant complexity:Creation may require significant complexity:
– recycling instances for performance reasonsrecycling instances for performance reasons
– conditionally creating instances from a familyconditionally creating instances from a family
of similar classesof similar classes
 In these instances, other patterns areIn these instances, other patterns are
available…available…
– We’ll learn about Factory and other patterns later…We’ll learn about Factory and other patterns later…
Information ExpertInformation Expert
pattern or principlepattern or principle
Name: Information ExpertName: Information Expert
Problem: How to assign responsibilities to objects?Problem: How to assign responsibilities to objects?
Solution: Assign responsibility to the class that hasSolution: Assign responsibility to the class that has
the information needed to fulfill it?the information needed to fulfill it?
 E.g., Board information needed to get a SquareE.g., Board information needed to get a Square
Benefits and ContraindicationsBenefits and Contraindications
 Facilitates information encapsulation:Facilitates information encapsulation: why?why?
– Classes use their own info to fulfill tasksClasses use their own info to fulfill tasks
 Encourages cohesive, lightweight class definitionsEncourages cohesive, lightweight class definitions
But:But:
 Information expert may contradict patterns ofInformation expert may contradict patterns of
Low Coupling and High CohesionLow Coupling and High Cohesion
 Remember separation of concerns principleRemember separation of concerns principle
for large sub-systemsfor large sub-systems
 I.e., keep “business” or application logicI.e., keep “business” or application logic
in one place, user interface in other place,in one place, user interface in other place,
database access in another place, etc.database access in another place, etc.
 Name:Name: Low CouplingLow Coupling
 Problem: How to reduce the impact ofProblem: How to reduce the impact of
change and encourage reuse?change and encourage reuse?
 Solution: Assign a responsibility so thatSolution: Assign a responsibility so that
coupling (linking classes) remains low.coupling (linking classes) remains low.
Low Coupling PatternLow Coupling Pattern
Why does the following designWhy does the following design
violate Low Coupling?violate Low Coupling?
Why is a better idea to leaveWhy is a better idea to leave
getSquare responsibility in Board?getSquare responsibility in Board?
Benefits & ContraindicationsBenefits & Contraindications
 Understandability: Classes are easierUnderstandability: Classes are easier
to understand in isolationto understand in isolation
 Maintainability: Classes aren’t affected byMaintainability: Classes aren’t affected by
changes in other componentschanges in other components
 Reusability: easier to grab hold of classesReusability: easier to grab hold of classes
But:But:
 Don’t sweat coupling to stable classes (inDon’t sweat coupling to stable classes (in
libraries or pervasive, well-tested classes)libraries or pervasive, well-tested classes)
Controller patternController pattern
 Name:Name: ControllerController
(see Model-View-Controller architecture)(see Model-View-Controller architecture)
 Problem: Who should be responsible for UIProblem: Who should be responsible for UI
events?events?
 Solution: Assign responsibility for receiving orSolution: Assign responsibility for receiving or
handling a system event in one of two ways:handling a system event in one of two ways:
– Represent the overall system (Represent the overall system (façadefaçade pattern)pattern)
– Represent a use case scenario within which theRepresent a use case scenario within which the
system event occurs (asystem event occurs (a sessionsession controller)controller)
Who is the controller of playGame operation?Who is the controller of playGame operation?
Figure 17.9, p. 288Figure 17.9, p. 288
What class represents the overall systemWhat class represents the overall system
or relevant use case scenario?or relevant use case scenario?
 Cohesion measures how strongly related andCohesion measures how strongly related and
focused are the responsibilities of an elementfocused are the responsibilities of an element
 Name:Name: High CohesionHigh Cohesion
 Problem: How to keep classes focused andProblem: How to keep classes focused and
manageable?manageable?
 Solution: Assign responsibility so that cohesionSolution: Assign responsibility so that cohesion
remains high.remains high.
High Cohesion patternHigh Cohesion pattern
How does the design on right promoteHow does the design on right promote
high cohesion?high cohesion?
Delegate responsibility & coordinate workDelegate responsibility & coordinate work
Benefits & ContraindicationsBenefits & Contraindications
 Understandability, maintainabilityUnderstandability, maintainability
 Complements Low CouplingComplements Low Coupling
But:But:
 Avoid grouping of responsibilities or code into oneAvoid grouping of responsibilities or code into one
class or component to simplify maintenance byclass or component to simplify maintenance by
one person.one person. Why?Why?
 Sometimes desirable to create less cohesive serverSometimes desirable to create less cohesive server
objects that provide an interface for manyobjects that provide an interface for many
operations, due to performance needs associatedoperations, due to performance needs associated
with remote objects and remote communicationwith remote objects and remote communication
SummarySummary
 Skillful assignment of responsibilities isSkillful assignment of responsibilities is
extremely important in object-oriented designextremely important in object-oriented design
(CRC cards are one technique)(CRC cards are one technique)
 Patterns are named problem/solution pairs thatPatterns are named problem/solution pairs that
codify good advice and principles related tocodify good advice and principles related to
assignment of responsibilitiesassignment of responsibilities
 GRASP identifies five patterns or principles:GRASP identifies five patterns or principles:
– Creator, Information Expert, Controller,Creator, Information Expert, Controller,
Low Coupling and High CohesionLow Coupling and High Cohesion

Más contenido relacionado

La actualidad más candente

Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2Sudarshan Dhondaley
 
Software Engineering Layered Technology Software Process Framework
Software Engineering  Layered Technology Software Process FrameworkSoftware Engineering  Layered Technology Software Process Framework
Software Engineering Layered Technology Software Process FrameworkJAINAM KAPADIYA
 
Writing Effective Use Cases
 Writing Effective Use Cases Writing Effective Use Cases
Writing Effective Use CasesHarsh Jegadeesan
 
Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software EngineeringManish Kumar
 
Design Concept software engineering
Design Concept software engineeringDesign Concept software engineering
Design Concept software engineeringDarshit Metaliya
 
Agile Methods - course notes
Agile Methods - course notesAgile Methods - course notes
Agile Methods - course notesEvan Leybourn
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns pptAman Jain
 
Object oriented methodologies
Object oriented methodologiesObject oriented methodologies
Object oriented methodologiesnaina-rani
 
Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns pptmkruthika
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagramsbarney92
 
Elaboration and domain model
Elaboration and domain modelElaboration and domain model
Elaboration and domain modelVignesh Saravanan
 
System Models in Software Engineering SE7
System Models in Software Engineering SE7System Models in Software Engineering SE7
System Models in Software Engineering SE7koolkampus
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented DesignAMITJain879
 

La actualidad más candente (20)

Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
UML
UMLUML
UML
 
Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2
 
Software Engineering Layered Technology Software Process Framework
Software Engineering  Layered Technology Software Process FrameworkSoftware Engineering  Layered Technology Software Process Framework
Software Engineering Layered Technology Software Process Framework
 
Writing Effective Use Cases
 Writing Effective Use Cases Writing Effective Use Cases
Writing Effective Use Cases
 
Design Pattern in Software Engineering
Design Pattern in Software EngineeringDesign Pattern in Software Engineering
Design Pattern in Software Engineering
 
Design Concept software engineering
Design Concept software engineeringDesign Concept software engineering
Design Concept software engineering
 
Agile Methods - course notes
Agile Methods - course notesAgile Methods - course notes
Agile Methods - course notes
 
OOAD
OOADOOAD
OOAD
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Software Architecture
Software ArchitectureSoftware Architecture
Software Architecture
 
Object oriented methodologies
Object oriented methodologiesObject oriented methodologies
Object oriented methodologies
 
Software design patterns ppt
Software design patterns pptSoftware design patterns ppt
Software design patterns ppt
 
Class notes
Class notesClass notes
Class notes
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagrams
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Elaboration and domain model
Elaboration and domain modelElaboration and domain model
Elaboration and domain model
 
System Models in Software Engineering SE7
System Models in Software Engineering SE7System Models in Software Engineering SE7
System Models in Software Engineering SE7
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 

Destacado (20)

GRASP Principles
GRASP PrinciplesGRASP Principles
GRASP Principles
 
Grasp principles
Grasp principlesGrasp principles
Grasp principles
 
GRASP Principles
GRASP PrinciplesGRASP Principles
GRASP Principles
 
14 grasp-1
14 grasp-114 grasp-1
14 grasp-1
 
8. operation contracts
8. operation contracts8. operation contracts
8. operation contracts
 
BIS 08a - Application Development - II Version 2
BIS 08a - Application Development - II Version 2BIS 08a - Application Development - II Version 2
BIS 08a - Application Development - II Version 2
 
Chapter03
Chapter03Chapter03
Chapter03
 
Chapter04
Chapter04Chapter04
Chapter04
 
OOA&D Lecture1
OOA&D Lecture1OOA&D Lecture1
OOA&D Lecture1
 
OOA&D Lecture 2 uml notations
OOA&D Lecture 2 uml notations OOA&D Lecture 2 uml notations
OOA&D Lecture 2 uml notations
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Chapter02
Chapter02Chapter02
Chapter02
 
Craig Larman - Scaling Lean & Agile Development
Craig Larman - Scaling Lean & Agile Development Craig Larman - Scaling Lean & Agile Development
Craig Larman - Scaling Lean & Agile Development
 
Unit 4 designing classes
Unit 4  designing classesUnit 4  designing classes
Unit 4 designing classes
 
Introduction to ARCHITECTURAL LANGUAGES
Introduction to ARCHITECTURAL LANGUAGESIntroduction to ARCHITECTURAL LANGUAGES
Introduction to ARCHITECTURAL LANGUAGES
 
SOLID & GRASP
SOLID & GRASPSOLID & GRASP
SOLID & GRASP
 
Rational Unified Process(Rup)
Rational Unified Process(Rup)Rational Unified Process(Rup)
Rational Unified Process(Rup)
 
Ooad
OoadOoad
Ooad
 
11 ooad uml-14
11 ooad uml-1411 ooad uml-14
11 ooad uml-14
 
Domain object model
Domain object modelDomain object model
Domain object model
 

Similar a 09 grasp

Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...gdgsurrey
 
Barga Data Science lecture 9
Barga Data Science lecture 9Barga Data Science lecture 9
Barga Data Science lecture 9Roger Barga
 
Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015
Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015
Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015Peter Beck
 
Keepler Data Tech | Entendiendo tus propios modelos predictivos
Keepler Data Tech | Entendiendo tus propios modelos predictivosKeepler Data Tech | Entendiendo tus propios modelos predictivos
Keepler Data Tech | Entendiendo tus propios modelos predictivosKeepler Data Tech
 
Creating Stable Assignments
Creating Stable AssignmentsCreating Stable Assignments
Creating Stable AssignmentsKevlin Henney
 
Boost Your Base Bootcamp - [Online & Offline] In Bangla
Boost Your Base Bootcamp - [Online & Offline] In BanglaBoost Your Base Bootcamp - [Online & Offline] In Bangla
Boost Your Base Bootcamp - [Online & Offline] In BanglaStack Learner
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringProtelo, Inc.
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldSaurabh Moody
 
Cs 1023 lec 9 design pattern (week 2)
Cs 1023 lec 9 design pattern (week 2)Cs 1023 lec 9 design pattern (week 2)
Cs 1023 lec 9 design pattern (week 2)stanbridge
 
2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and Web2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and WebMarco Parenzan
 
Root cause of community problem for this discussion, you will i
Root cause of community problem for this discussion, you will iRoot cause of community problem for this discussion, you will i
Root cause of community problem for this discussion, you will issusere73ce3
 
Java Design Pattern Interview Questions
Java Design Pattern Interview QuestionsJava Design Pattern Interview Questions
Java Design Pattern Interview Questionsjbashask
 
The Architecture of Uncertainty
The Architecture of UncertaintyThe Architecture of Uncertainty
The Architecture of UncertaintyKevlin Henney
 
Google Interview Prep Guide Software Engineer
Google Interview Prep Guide Software EngineerGoogle Interview Prep Guide Software Engineer
Google Interview Prep Guide Software EngineerLewis Lin 🦊
 

Similar a 09 grasp (20)

Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
 
Barga Data Science lecture 9
Barga Data Science lecture 9Barga Data Science lecture 9
Barga Data Science lecture 9
 
Unit 4
Unit 4Unit 4
Unit 4
 
How to write a project proposal
How to write a project proposalHow to write a project proposal
How to write a project proposal
 
Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015
Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015
Workshop 'Facilitation Dojo' at ScrumGathering Praque_2015
 
Keepler Data Tech | Entendiendo tus propios modelos predictivos
Keepler Data Tech | Entendiendo tus propios modelos predictivosKeepler Data Tech | Entendiendo tus propios modelos predictivos
Keepler Data Tech | Entendiendo tus propios modelos predictivos
 
Creating Stable Assignments
Creating Stable AssignmentsCreating Stable Assignments
Creating Stable Assignments
 
Boost Your Base Bootcamp - [Online & Offline] In Bangla
Boost Your Base Bootcamp - [Online & Offline] In BanglaBoost Your Base Bootcamp - [Online & Offline] In Bangla
Boost Your Base Bootcamp - [Online & Offline] In Bangla
 
030325+seminar+scg+iam.ppt
030325+seminar+scg+iam.ppt030325+seminar+scg+iam.ppt
030325+seminar+scg+iam.ppt
 
Why Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software EngineeringWhy Design Patterns Are Important In Software Engineering
Why Design Patterns Are Important In Software Engineering
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Writing Quality Code
Writing Quality CodeWriting Quality Code
Writing Quality Code
 
The Modlet Pattern
The Modlet PatternThe Modlet Pattern
The Modlet Pattern
 
Cs 1023 lec 9 design pattern (week 2)
Cs 1023 lec 9 design pattern (week 2)Cs 1023 lec 9 design pattern (week 2)
Cs 1023 lec 9 design pattern (week 2)
 
2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and Web2015.01.09 - Writing Modern Applications for Mobile and Web
2015.01.09 - Writing Modern Applications for Mobile and Web
 
Root cause of community problem for this discussion, you will i
Root cause of community problem for this discussion, you will iRoot cause of community problem for this discussion, you will i
Root cause of community problem for this discussion, you will i
 
Java Design Pattern Interview Questions
Java Design Pattern Interview QuestionsJava Design Pattern Interview Questions
Java Design Pattern Interview Questions
 
Presentation
PresentationPresentation
Presentation
 
The Architecture of Uncertainty
The Architecture of UncertaintyThe Architecture of Uncertainty
The Architecture of Uncertainty
 
Google Interview Prep Guide Software Engineer
Google Interview Prep Guide Software EngineerGoogle Interview Prep Guide Software Engineer
Google Interview Prep Guide Software Engineer
 

Último

Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Call Girls Mumbai
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 

Último (20)

Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 

09 grasp

  • 1. GRASP: Designing ObjectsGRASP: Designing Objects with Responsibilitieswith Responsibilities Applying UML and PatternsApplying UML and Patterns Craig LarmanCraig Larman Chapter 17Chapter 17 Glenn D. Blank CSE432, Lehigh UniversityGlenn D. Blank CSE432, Lehigh University
  • 2. Chapter Learning ObjectivesChapter Learning Objectives  Learn about design patternsLearn about design patterns  Learn how to apply five GRASP patternsLearn how to apply five GRASP patterns  You’ve learned about static class diagramsYou’ve learned about static class diagrams and dynamic interaction diagramsand dynamic interaction diagrams  UML is just notation; now you need to learnUML is just notation; now you need to learn how to make effective use of the notationhow to make effective use of the notation  UML modeling is an art, guided by principlesUML modeling is an art, guided by principles
  • 3. Design patterns in architectureDesign patterns in architecture  AA patternpattern is ais a recurringrecurring solutionsolution to a standardto a standard problemproblem,, in ain a contextcontext..  Christopher Alexander, professor of architecture…Christopher Alexander, professor of architecture… – Why is what a prof of architectureWhy is what a prof of architecture says relevant to software?says relevant to software? – ““A pattern describes a problemA pattern describes a problem which occurs over and over againwhich occurs over and over again in our environment, and thenin our environment, and then describes the core of the solutiondescribes the core of the solution to that problem, in such a way thatto that problem, in such a way that you can use this solution a millionyou can use this solution a million times over, without ever doing ittimes over, without ever doing it the same way twice.”the same way twice.”
  • 4. Design and dress patternsDesign and dress patterns  Jim Coplein, a software engineer:Jim Coplein, a software engineer: ““I like to relate this definition to dress patterns …I like to relate this definition to dress patterns … I could tell you how toI could tell you how to make a dress by specifyingmake a dress by specifying the route of a scissorsthe route of a scissors through a piece of cloththrough a piece of cloth in terms of angles andin terms of angles and lengths of cut. Or, I couldlengths of cut. Or, I could give you a pattern.give you a pattern. Reading the specification,Reading the specification, you would have no ideayou would have no idea what was being built or if you had built the right thing whenwhat was being built or if you had built the right thing when you were finished. The pattern foreshadows the product:you were finished. The pattern foreshadows the product: it is the rule for making the thing, but it is also,it is the rule for making the thing, but it is also, in many respects, the thing itself.”in many respects, the thing itself.”
  • 5. Patterns in engineeringPatterns in engineering  How do other engineers find and use patterns?How do other engineers find and use patterns? – Mature engineering disciplines haveMature engineering disciplines have handbookshandbooks describing successful solutions to known problemsdescribing successful solutions to known problems – Automobile designers don't design cars from scratchAutomobile designers don't design cars from scratch using the laws of physicsusing the laws of physics – Instead, theyInstead, they reusereuse standard designs with successfulstandard designs with successful track records, learning from experiencetrack records, learning from experience – Should software engineers make use of patterns?Should software engineers make use of patterns? Why?Why? – ““Be sure that you make everything according to the patternBe sure that you make everything according to the pattern I have shown you here on the mountain.” Exodus 25:40.I have shown you here on the mountain.” Exodus 25:40.  Developing software from scratch is also expensiveDeveloping software from scratch is also expensive – Patterns supportPatterns support reusereuse of software architecture designof software architecture design
  • 6. Definitions and namesDefinitions and names  Alexander: “AAlexander: “A patternpattern is ais a recurringrecurring solutionsolution to a standardto a standard problemproblem, in a, in a contextcontext.”.”  Larman: “In OO design, aLarman: “In OO design, a patternpattern is a namedis a named description of a problem and solution that can bedescription of a problem and solution that can be applied in new contexts; ideally,applied in new contexts; ideally, a pattern advises us on how to apply the solutiona pattern advises us on how to apply the solution in varying circumstances and considersin varying circumstances and considers the forces and trade-offs.”the forces and trade-offs.”  How is Larman’s definition similar to Alexander’s?How is Larman’s definition similar to Alexander’s?  How are these definitions significantly different?How are these definitions significantly different?
  • 7.  Patterns have suggestive names:Patterns have suggestive names: – Arched Columns Pattern, Easy Toddler Dress Pattern,Arched Columns Pattern, Easy Toddler Dress Pattern, etc.etc.  Why is naming a pattern or principle helpful?Why is naming a pattern or principle helpful? – It supports chunking and incorporating that conceptIt supports chunking and incorporating that concept into our understanding and memoryinto our understanding and memory – It facilitates communicationIt facilitates communication Naming Patterns—important!Naming Patterns—important! Star and Plume Quilt
  • 8. GRASPGRASP  Name chosen to suggest the importance ofName chosen to suggest the importance of graspgrasping fundamental principles to successfullying fundamental principles to successfully design object-oriented softwaredesign object-oriented software  Acronym forAcronym for GGeneraleneral RResponsibilityesponsibility AAssignmentssignment SSoftwareoftware PPatternsatterns  Describe fundamental principles ofDescribe fundamental principles of object design and responsibilityobject design and responsibility  Expressed as patternsExpressed as patterns
  • 9. Five GRASP patterns:Five GRASP patterns:  CreatorCreator  Information ExpertInformation Expert  Low CouplingLow Coupling  ControllerController  High CohesionHigh Cohesion
  • 10. Creator patternCreator pattern Name:Name: CreatorCreator Problem: Who creates an instance of A?Problem: Who creates an instance of A? Solution: Assign class B the responsibilitySolution: Assign class B the responsibility to create an instance of class A if one ofto create an instance of class A if one of these is true (the more the better):these is true (the more the better):  B contains or aggregates A (in a collection)B contains or aggregates A (in a collection)  B records AB records A  B closely uses AB closely uses A  B has the initializing data for AB has the initializing data for A
  • 11. Who creates the Squares?Who creates the Squares? Figure 17.3, page 283Figure 17.3, page 283
  • 12. How does Create pattern lead toHow does Create pattern lead to this partial Sequence diagram?this partial Sequence diagram? Figure 17.4, page 283Figure 17.4, page 283
  • 13. How does Create pattern developHow does Create pattern develop this Design Class Diagram (DCD)?this Design Class Diagram (DCD)? Figure 17.5 , page 283Figure 17.5 , page 283 Board has a composite aggregation relationship with Square • I.e., Board contains a collection of Squares
  • 14. Discussion of Creator patternDiscussion of Creator pattern  Responsibilities for object creation are commonResponsibilities for object creation are common  Connect an object to its creator when:Connect an object to its creator when: – Aggregator aggregates PartAggregator aggregates Part – Container contains ContentContainer contains Content – Recorder recordsRecorder records – Initializing data passed in during creationInitializing data passed in during creation
  • 15. Contraindications or caveatsContraindications or caveats  Creation may require significant complexity:Creation may require significant complexity: – recycling instances for performance reasonsrecycling instances for performance reasons – conditionally creating instances from a familyconditionally creating instances from a family of similar classesof similar classes  In these instances, other patterns areIn these instances, other patterns are available…available… – We’ll learn about Factory and other patterns later…We’ll learn about Factory and other patterns later…
  • 16. Information ExpertInformation Expert pattern or principlepattern or principle Name: Information ExpertName: Information Expert Problem: How to assign responsibilities to objects?Problem: How to assign responsibilities to objects? Solution: Assign responsibility to the class that hasSolution: Assign responsibility to the class that has the information needed to fulfill it?the information needed to fulfill it?  E.g., Board information needed to get a SquareE.g., Board information needed to get a Square
  • 17. Benefits and ContraindicationsBenefits and Contraindications  Facilitates information encapsulation:Facilitates information encapsulation: why?why? – Classes use their own info to fulfill tasksClasses use their own info to fulfill tasks  Encourages cohesive, lightweight class definitionsEncourages cohesive, lightweight class definitions But:But:  Information expert may contradict patterns ofInformation expert may contradict patterns of Low Coupling and High CohesionLow Coupling and High Cohesion  Remember separation of concerns principleRemember separation of concerns principle for large sub-systemsfor large sub-systems  I.e., keep “business” or application logicI.e., keep “business” or application logic in one place, user interface in other place,in one place, user interface in other place, database access in another place, etc.database access in another place, etc.
  • 18.  Name:Name: Low CouplingLow Coupling  Problem: How to reduce the impact ofProblem: How to reduce the impact of change and encourage reuse?change and encourage reuse?  Solution: Assign a responsibility so thatSolution: Assign a responsibility so that coupling (linking classes) remains low.coupling (linking classes) remains low. Low Coupling PatternLow Coupling Pattern
  • 19. Why does the following designWhy does the following design violate Low Coupling?violate Low Coupling? Why is a better idea to leaveWhy is a better idea to leave getSquare responsibility in Board?getSquare responsibility in Board?
  • 20. Benefits & ContraindicationsBenefits & Contraindications  Understandability: Classes are easierUnderstandability: Classes are easier to understand in isolationto understand in isolation  Maintainability: Classes aren’t affected byMaintainability: Classes aren’t affected by changes in other componentschanges in other components  Reusability: easier to grab hold of classesReusability: easier to grab hold of classes But:But:  Don’t sweat coupling to stable classes (inDon’t sweat coupling to stable classes (in libraries or pervasive, well-tested classes)libraries or pervasive, well-tested classes)
  • 21. Controller patternController pattern  Name:Name: ControllerController (see Model-View-Controller architecture)(see Model-View-Controller architecture)  Problem: Who should be responsible for UIProblem: Who should be responsible for UI events?events?  Solution: Assign responsibility for receiving orSolution: Assign responsibility for receiving or handling a system event in one of two ways:handling a system event in one of two ways: – Represent the overall system (Represent the overall system (façadefaçade pattern)pattern) – Represent a use case scenario within which theRepresent a use case scenario within which the system event occurs (asystem event occurs (a sessionsession controller)controller)
  • 22. Who is the controller of playGame operation?Who is the controller of playGame operation? Figure 17.9, p. 288Figure 17.9, p. 288 What class represents the overall systemWhat class represents the overall system or relevant use case scenario?or relevant use case scenario?
  • 23.  Cohesion measures how strongly related andCohesion measures how strongly related and focused are the responsibilities of an elementfocused are the responsibilities of an element  Name:Name: High CohesionHigh Cohesion  Problem: How to keep classes focused andProblem: How to keep classes focused and manageable?manageable?  Solution: Assign responsibility so that cohesionSolution: Assign responsibility so that cohesion remains high.remains high. High Cohesion patternHigh Cohesion pattern
  • 24. How does the design on right promoteHow does the design on right promote high cohesion?high cohesion? Delegate responsibility & coordinate workDelegate responsibility & coordinate work
  • 25. Benefits & ContraindicationsBenefits & Contraindications  Understandability, maintainabilityUnderstandability, maintainability  Complements Low CouplingComplements Low Coupling But:But:  Avoid grouping of responsibilities or code into oneAvoid grouping of responsibilities or code into one class or component to simplify maintenance byclass or component to simplify maintenance by one person.one person. Why?Why?  Sometimes desirable to create less cohesive serverSometimes desirable to create less cohesive server objects that provide an interface for manyobjects that provide an interface for many operations, due to performance needs associatedoperations, due to performance needs associated with remote objects and remote communicationwith remote objects and remote communication
  • 26. SummarySummary  Skillful assignment of responsibilities isSkillful assignment of responsibilities is extremely important in object-oriented designextremely important in object-oriented design (CRC cards are one technique)(CRC cards are one technique)  Patterns are named problem/solution pairs thatPatterns are named problem/solution pairs that codify good advice and principles related tocodify good advice and principles related to assignment of responsibilitiesassignment of responsibilities  GRASP identifies five patterns or principles:GRASP identifies five patterns or principles: – Creator, Information Expert, Controller,Creator, Information Expert, Controller, Low Coupling and High CohesionLow Coupling and High Cohesion