SlideShare uma empresa Scribd logo
1 de 19
AmirdhaGopalRajendran X-Conf  Thoughtworks, Chennai Patterns of assigning Responsibilities The critical design tool for software development is  a MIND well educated in DESIGN PRINCIPLES.  – Craig Larman
Setting the Context Pattern Responsibility Domain Model Patterns Creator Information Expert Pure Fabrication Indirection Polymorphism Protected Variation Related Patterns References Introduction Life can only be understood backwards, but it must be lived forwards. – Soren Kierkegaard
Pattern is an abstractsolution to a recurring problem, in a particular context. Larman: A good pattern is a named and well-knownproblem/solution pair that can be applied in new contexts. Design Pattern:  Notto express new design ideas.  Codify Existing tried-and-true knowledge, idioms and principles GRASP - General Responsibility Assignment Software Patterns or Principles.  Pattern One person’s pattern is another person’s primitive building block. – GoF
Responsibilities are obligations of an object in terms of its behaviour. Doing: Doing something itself, such as creating an object or doing a calculation Initiating action in other objects Controlling and coordinating activities in other objects. Knowing: Knowing about private encapsulated data Knowing about related objects Knowing about things it can derive or calculate Responsibility Understanding responsibilities is key to good object-oriented design.  -Martin Fowler
Domain Model It’s all very well in practice, but it will never work in theory. -Management Maxim
Who is responsible for creating SalesLineItem?
Who should be responsible for creating a new instance of some class? Assign class B the responsibility to create an instance of class A if one or more of the following is true: B aggregates A B contains A B records instance of A objects B closely use A objects B passes initializing data to A Delegate complex creation logic to Concrete Factory or Abstract Factory. Benefits Low Coupling Creator
How to determine the grandTotal?
What is the general principle of assigning responsibilities to objects? Assign a responsibility to the information expert – the class that has the information necessary to fulfill the responsibility. ContraIndication Undesirable in some situations, because of coupling and cohesion Benefits Information Encapsulation Distribution of behaviour – more cohesive “lightweight” class definitions Information Expert
How to Save the Sale to Database? SaleRepository Sale Load(intsaleId) void Save(Sale sale) …
What object should have the responsibility, when not to violate High Cohesion and Low Coupling? Assign a highly cohesive set of responsibilities to an artificial class, that does not represent a problem domain, in order to support high cohesion, low coupling, and reuse. Design of Objects Representational Decomposition – Domain Things Behavioral Decomposition – Algorithms ContraIndications Overuse – too many behavior objects. Benefits High Cohesion Reuse potential because of  fine-grained Pure Fabrication. Virtually, all design patterns are Pure Fabrications Pure Fabrication
How to avoid direct coupling between Sale and External Tax Systems?
Where to assign a responsibility, to avoid direct coupling between two things?  Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. Benefits Low Coupling Many pure fabrications are generated because of Indirection Many Existing design patterns are specialization of Indirection. Indirection Most problems in computer science can be solved by  another level of indirection. Most problems in performance can be solved by  removing another level of indirection .
How to handle multiple Payment Types?
How handle alternatives based on type?  When alternate behaviours are selected based on the type of an object, use polymorphic method call to select the behaviour, rather than using if statement to test the type. “Giving the same name to services in different objects” ContraIndications Speculative “future-proofing” – unnecessary effort Benefits: New variations are easy to add. Clients are not affected. Polymorphism
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? Identify points of predicted variation or instability; assign responsibilities to create a stable interface around them. Very important, fundamental principle of software design. Points of Change (Hot spots)   Variation Point, Evolution Point Mechanisms motivated by PV Service Lookups, Virtual Machines, Standard Languages, etc… Same as Information Hiding and Open-Closed Priciple. Protected Variation
Controller High Cohesion Low Coupling Law of Demeter Principle of Least Knowledge Only talk to your immediate friends Related Patterns Not everything that can be counted counts,  and not everything that counts can be counted. -Albert Einstein
References Measuring programming progress by lines of code  is like measuring aircraft building progress by weight -Bill Gates
Thank you Intelligence is the ability to avoid doing work,  yet getting the work done.  -LinusTorvalds

Mais conteúdo relacionado

Mais procurados

soft computing manoj
soft computing manojsoft computing manoj
soft computing manojManoj Yadav
 
Soft computing abstracts
Soft computing abstractsSoft computing abstracts
Soft computing abstractsabctry
 
An Introduction to Soft Computing
An Introduction to Soft ComputingAn Introduction to Soft Computing
An Introduction to Soft ComputingTameem Ahmad
 
Introduction to Soft Computing
Introduction to Soft Computing Introduction to Soft Computing
Introduction to Soft Computing Aakash Kumar
 
soft-computing
 soft-computing soft-computing
soft-computingstudent
 
Application of soft computing techniques in electrical engineering
Application of soft computing techniques in electrical engineeringApplication of soft computing techniques in electrical engineering
Application of soft computing techniques in electrical engineeringSouvik Dutta
 
Knowledgebase vs Database
Knowledgebase vs DatabaseKnowledgebase vs Database
Knowledgebase vs DatabaseCJ Jenkins
 

Mais procurados (17)

soft computing manoj
soft computing manojsoft computing manoj
soft computing manoj
 
Soft computing abstracts
Soft computing abstractsSoft computing abstracts
Soft computing abstracts
 
Basics of Soft Computing
Basics of Soft  Computing Basics of Soft  Computing
Basics of Soft Computing
 
Soft computing
Soft computing Soft computing
Soft computing
 
An Introduction to Soft Computing
An Introduction to Soft ComputingAn Introduction to Soft Computing
An Introduction to Soft Computing
 
Introduction to Soft Computing
Introduction to Soft Computing Introduction to Soft Computing
Introduction to Soft Computing
 
Introduction to Soft Computing
Introduction to Soft ComputingIntroduction to Soft Computing
Introduction to Soft Computing
 
Soft computing
Soft computingSoft computing
Soft computing
 
Knowledge based agents
Knowledge based agentsKnowledge based agents
Knowledge based agents
 
Soft computing01
Soft computing01Soft computing01
Soft computing01
 
Final grasp ASE
Final grasp ASEFinal grasp ASE
Final grasp ASE
 
Kiran computer
Kiran computerKiran computer
Kiran computer
 
Soft computing
Soft computingSoft computing
Soft computing
 
soft-computing
 soft-computing soft-computing
soft-computing
 
Application of soft computing techniques in electrical engineering
Application of soft computing techniques in electrical engineeringApplication of soft computing techniques in electrical engineering
Application of soft computing techniques in electrical engineering
 
SoftComputing1
SoftComputing1SoftComputing1
SoftComputing1
 
Knowledgebase vs Database
Knowledgebase vs DatabaseKnowledgebase vs Database
Knowledgebase vs Database
 

Semelhante a Patterns of Assigning Responsibilities

CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV pkaviya
 
Advanced oop laws, principles, idioms
Advanced oop laws, principles, idiomsAdvanced oop laws, principles, idioms
Advanced oop laws, principles, idiomsClint Edmonson
 
Basics of object oriented programming
Basics of object oriented programmingBasics of object oriented programming
Basics of object oriented programmingNitin Kumar Kashyap
 
Advanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, IdiomsAdvanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, IdiomsClint Edmonson
 
The Black Box: Interpretability, Reproducibility, and Data Management
The Black Box: Interpretability, Reproducibility, and Data ManagementThe Black Box: Interpretability, Reproducibility, and Data Management
The Black Box: Interpretability, Reproducibility, and Data Managementmark madsen
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_pptagnes_crepet
 
Four principles seminar manageware seminar
Four principles seminar   manageware seminarFour principles seminar   manageware seminar
Four principles seminar manageware seminarManageware
 
Algorithmic thinking and digital fabrication (1) (2)
Algorithmic thinking and digital fabrication (1) (2)Algorithmic thinking and digital fabrication (1) (2)
Algorithmic thinking and digital fabrication (1) (2)Prabhat Kumar
 
Algorithmic thinking and digital fabrication
Algorithmic thinking and digital fabricationAlgorithmic thinking and digital fabrication
Algorithmic thinking and digital fabricationharshit2013
 
The Role Of Ontology In Modern Expert Systems Dallas 2008
The Role Of Ontology In Modern Expert Systems   Dallas   2008The Role Of Ontology In Modern Expert Systems   Dallas   2008
The Role Of Ontology In Modern Expert Systems Dallas 2008Jason Morris
 
Structured Software Design
Structured Software DesignStructured Software Design
Structured Software DesignGiorgio Zoppi
 
Bt8901 objective oriented systems1
Bt8901 objective oriented systems1Bt8901 objective oriented systems1
Bt8901 objective oriented systems1Techglyphs
 
Operationalizing Machine Learning in the Enterprise
Operationalizing Machine Learning in the EnterpriseOperationalizing Machine Learning in the Enterprise
Operationalizing Machine Learning in the Enterprisemark madsen
 
Technology in financial services
Technology in financial servicesTechnology in financial services
Technology in financial servicesLuis Caldeira
 
Technology in financial services
Technology in financial servicesTechnology in financial services
Technology in financial servicesLuis Caldeira
 
Rapid software evolution
Rapid software evolutionRapid software evolution
Rapid software evolutionborislav
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 

Semelhante a Patterns of Assigning Responsibilities (20)

CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV CS8592 Object Oriented Analysis & Design - UNIT IV
CS8592 Object Oriented Analysis & Design - UNIT IV
 
Advanced oop laws, principles, idioms
Advanced oop laws, principles, idiomsAdvanced oop laws, principles, idioms
Advanced oop laws, principles, idioms
 
Oops Concepts
Oops ConceptsOops Concepts
Oops Concepts
 
Basics of object oriented programming
Basics of object oriented programmingBasics of object oriented programming
Basics of object oriented programming
 
Advanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, IdiomsAdvanced OOP - Laws, Principles, Idioms
Advanced OOP - Laws, Principles, Idioms
 
The Black Box: Interpretability, Reproducibility, and Data Management
The Black Box: Interpretability, Reproducibility, and Data ManagementThe Black Box: Interpretability, Reproducibility, and Data Management
The Black Box: Interpretability, Reproducibility, and Data Management
 
Writing Quality Code
Writing Quality CodeWriting Quality Code
Writing Quality Code
 
Design poo my_jug_en_ppt
Design poo my_jug_en_pptDesign poo my_jug_en_ppt
Design poo my_jug_en_ppt
 
CS8592-OOAD Lecture Notes Unit-4
CS8592-OOAD Lecture Notes Unit-4CS8592-OOAD Lecture Notes Unit-4
CS8592-OOAD Lecture Notes Unit-4
 
Four principles seminar manageware seminar
Four principles seminar   manageware seminarFour principles seminar   manageware seminar
Four principles seminar manageware seminar
 
Algorithmic thinking and digital fabrication (1) (2)
Algorithmic thinking and digital fabrication (1) (2)Algorithmic thinking and digital fabrication (1) (2)
Algorithmic thinking and digital fabrication (1) (2)
 
Algorithmic thinking and digital fabrication
Algorithmic thinking and digital fabricationAlgorithmic thinking and digital fabrication
Algorithmic thinking and digital fabrication
 
The Role Of Ontology In Modern Expert Systems Dallas 2008
The Role Of Ontology In Modern Expert Systems   Dallas   2008The Role Of Ontology In Modern Expert Systems   Dallas   2008
The Role Of Ontology In Modern Expert Systems Dallas 2008
 
Structured Software Design
Structured Software DesignStructured Software Design
Structured Software Design
 
Bt8901 objective oriented systems1
Bt8901 objective oriented systems1Bt8901 objective oriented systems1
Bt8901 objective oriented systems1
 
Operationalizing Machine Learning in the Enterprise
Operationalizing Machine Learning in the EnterpriseOperationalizing Machine Learning in the Enterprise
Operationalizing Machine Learning in the Enterprise
 
Technology in financial services
Technology in financial servicesTechnology in financial services
Technology in financial services
 
Technology in financial services
Technology in financial servicesTechnology in financial services
Technology in financial services
 
Rapid software evolution
Rapid software evolutionRapid software evolution
Rapid software evolution
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 

Último

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

Patterns of Assigning Responsibilities

  • 1. AmirdhaGopalRajendran X-Conf Thoughtworks, Chennai Patterns of assigning Responsibilities The critical design tool for software development is a MIND well educated in DESIGN PRINCIPLES. – Craig Larman
  • 2. Setting the Context Pattern Responsibility Domain Model Patterns Creator Information Expert Pure Fabrication Indirection Polymorphism Protected Variation Related Patterns References Introduction Life can only be understood backwards, but it must be lived forwards. – Soren Kierkegaard
  • 3. Pattern is an abstractsolution to a recurring problem, in a particular context. Larman: A good pattern is a named and well-knownproblem/solution pair that can be applied in new contexts. Design Pattern: Notto express new design ideas. Codify Existing tried-and-true knowledge, idioms and principles GRASP - General Responsibility Assignment Software Patterns or Principles. Pattern One person’s pattern is another person’s primitive building block. – GoF
  • 4. Responsibilities are obligations of an object in terms of its behaviour. Doing: Doing something itself, such as creating an object or doing a calculation Initiating action in other objects Controlling and coordinating activities in other objects. Knowing: Knowing about private encapsulated data Knowing about related objects Knowing about things it can derive or calculate Responsibility Understanding responsibilities is key to good object-oriented design. -Martin Fowler
  • 5. Domain Model It’s all very well in practice, but it will never work in theory. -Management Maxim
  • 6. Who is responsible for creating SalesLineItem?
  • 7. Who should be responsible for creating a new instance of some class? Assign class B the responsibility to create an instance of class A if one or more of the following is true: B aggregates A B contains A B records instance of A objects B closely use A objects B passes initializing data to A Delegate complex creation logic to Concrete Factory or Abstract Factory. Benefits Low Coupling Creator
  • 8. How to determine the grandTotal?
  • 9. What is the general principle of assigning responsibilities to objects? Assign a responsibility to the information expert – the class that has the information necessary to fulfill the responsibility. ContraIndication Undesirable in some situations, because of coupling and cohesion Benefits Information Encapsulation Distribution of behaviour – more cohesive “lightweight” class definitions Information Expert
  • 10. How to Save the Sale to Database? SaleRepository Sale Load(intsaleId) void Save(Sale sale) …
  • 11. What object should have the responsibility, when not to violate High Cohesion and Low Coupling? Assign a highly cohesive set of responsibilities to an artificial class, that does not represent a problem domain, in order to support high cohesion, low coupling, and reuse. Design of Objects Representational Decomposition – Domain Things Behavioral Decomposition – Algorithms ContraIndications Overuse – too many behavior objects. Benefits High Cohesion Reuse potential because of fine-grained Pure Fabrication. Virtually, all design patterns are Pure Fabrications Pure Fabrication
  • 12. How to avoid direct coupling between Sale and External Tax Systems?
  • 13. Where to assign a responsibility, to avoid direct coupling between two things? Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. Benefits Low Coupling Many pure fabrications are generated because of Indirection Many Existing design patterns are specialization of Indirection. Indirection Most problems in computer science can be solved by another level of indirection. Most problems in performance can be solved by removing another level of indirection .
  • 14. How to handle multiple Payment Types?
  • 15. How handle alternatives based on type? When alternate behaviours are selected based on the type of an object, use polymorphic method call to select the behaviour, rather than using if statement to test the type. “Giving the same name to services in different objects” ContraIndications Speculative “future-proofing” – unnecessary effort Benefits: New variations are easy to add. Clients are not affected. Polymorphism
  • 16. 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? Identify points of predicted variation or instability; assign responsibilities to create a stable interface around them. Very important, fundamental principle of software design. Points of Change (Hot spots) Variation Point, Evolution Point Mechanisms motivated by PV Service Lookups, Virtual Machines, Standard Languages, etc… Same as Information Hiding and Open-Closed Priciple. Protected Variation
  • 17. Controller High Cohesion Low Coupling Law of Demeter Principle of Least Knowledge Only talk to your immediate friends Related Patterns Not everything that can be counted counts, and not everything that counts can be counted. -Albert Einstein
  • 18. References Measuring programming progress by lines of code is like measuring aircraft building progress by weight -Bill Gates
  • 19. Thank you Intelligence is the ability to avoid doing work, yet getting the work done.  -LinusTorvalds

Notas do Editor

  1. Common Relationships - Composite aggregates Part - Container contains Content - Recorder records RecordedA composite object is an excellent candidate to make its parts.When creation requires significant complexity, delegate creation to a helper class called Concrete Factory or Abstract Factory.Benefits: Low coupling is supported
  2. Frequently used in the assignment of responsibilities.Undesirable in some situations, because of problems in coupling and cohesion.Eg: Who should be responsible for saving a sale in a database?By Expert, it should be in Sale class, which leads to cohesion, coupling and duplication problem.Benefits: - Information encapsulation is maintained, which supports low coupling. - Distribution of behaviour across the classes, thus encouraging more cohesive “lightweight” class definitions.
  3. What object should have the responsibility, when you do not wantto violate High Cohesion and Low Coupling, or other goals, but solutions offered by Expert (for example) are not appropriate?Pure Fabrication – Idiom – implies making something up.The responsibilities are shifted from the Expert class to the Pure Fabrication.Design of Objects:Representational Decomposition – Represents things in DomainBehavioral Decomposition - AlgorithmsPreserves low coupling and high cohesion.Virtually, all design patterns are Pure Fabrications.
  4. Where to assign a responsibility, to avoid direct coupling between two things? How to de-couple objects so that low coupling is supported and reuse potential remains higher?Pure Fabrications are generated because of Indirection.
  5. Very important, fundamental principle of software design.Eg:Data Driven DesignsService LookupUniform AccessStandard LanguagesTwo points of change: Variation Point Evolution PointInformation Hiding: Hide Information about the design from other modules, at the points of difficulty or likely change.Open Closed Principle: Modules should be both open (for extension; adaptable) and closed (the module is closed to modification in ways that affect clients.)ContraIndications and Benefits are same as Polymorphism.
  6. Controller:What first object beyond the UI layer receives and coordinates (“Controls”) a system operation?Assign the responsibility to an object representing one of these choicesRepresents the overall “system”, a “root object” (façade controller)Represents a use case scenario (session controller)Law of DemeterWithin a method, messages should only be sent to the following objectsThe this object (or self)A parameter of the methodAn attribute of thisAn element of a collection which is an attribute of this.An object created within the method.