SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Recently uploaded (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

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

Editor's Notes

  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.