SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
You want to encapsulate at all times.



This initializer is focused on initialization. Setters
guard their respective attributes (e.g. in this case,
legal values for gender and status).


Hide direct attribute access even within the class.
Public API should be
useful without
having to view
implementation
details.



If this is not the
case, improve your
method signatures.
!
How often do you
look at public API
method
implementations
offered by Gems?
Why do you people
indent private and
protected methods?



When followed
consistently by a
team, developers
then know indented
code is likely the
implementation
details of a class.
Modules and
concerns seem
convenient, but
there are some
cons.



They require
reviewing an out of
view file to know the
API.
!
Spurious methods
can enter into the
API.
!
Alternative:
!
Consider class-based composition.
!
Needs no explanation. We’ve all done it.
Export coupling. FeedingTube is coupled to a receiver
role which is played by the SlaveHuman instance.
Nil coupling. No coupling, but you better have two
instances or your program is uninteresting.
!
Or consider String or Math classes as better examples
of nil coupling; the above example could be argued as
coupled. :)
Beware of methods on a class that seem
to be using accessors or methods of another
class and few of its own.
!
You may be writing a method that belongs on
that other class.
!
Changes there may break you here.
There could be some argument here if a SlaveHuman
is really just a role that a Human plays.
!
The decision hinges on new and different behavior.
This model implies that the Human doesn’t digest
food.



This is not true in the real world, but our model need
only apply to the problem domain.
Services
Really en vogue now. Extract it to a service!
A service should mediate between classes only when it
makes no sense for any one of them to do so
themselves. Consider whether one class has
authoritative knowledge before separating out to a
service.
Lots of services yield an anemic object model; classes
are stripped of behavior they should own.
Services are great, just be sure you’ve thought it through.
Problem
A room requires heat when its temperature is
greater than 72 and occupied.
!
How shall we code it?
Often seen. LeakyRoom leaks its details to allow
the GodFurnace to take on too much responsibility.
Well-place responsibilities. Did it all start with
discipline at the public API level?
God Classes
• There are two kinds of God classes:
• One that performs services by orchestrating
object collaborations. Less data, more
methods.
• One that contains data that others need.
Fewer methods, lots of data.
Sometimes the real world is the wrong thing to model
after.
!
In this case, the building is more authoritative on
targeting and damage, so the messaging is flipped.
!
The wonderful thing about O-O design is that you get
to create your own world which abides by your laws of
physics.
Down the rabbit hole of
Object thinking...
Free your mind
Tank, we need more
O-O KNOWLEDGE
programs...
Object Design
DDD
Code Patterns
10 Object-Oriented Design Heuristics for Rubyists

Weitere ähnliche Inhalte

Andere mochten auch

I Realize Lean Startup Hack-nov2010
I Realize Lean Startup Hack-nov2010I Realize Lean Startup Hack-nov2010
I Realize Lean Startup Hack-nov2010TOP-IX Consortium
 
Heuristics 101: Understanding and Applying Design Principles
Heuristics 101: Understanding and Applying Design PrinciplesHeuristics 101: Understanding and Applying Design Principles
Heuristics 101: Understanding and Applying Design PrinciplesKamaria Campbell
 
Towards the Design of Heuristics by Means of Self-Assembly
Towards the Design of Heuristics by Means of Self-AssemblyTowards the Design of Heuristics by Means of Self-Assembly
Towards the Design of Heuristics by Means of Self-AssemblyGerman Terrazas
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design PresentationKawsar Ahmed
 
User Experience Design Heuristics
User Experience Design HeuristicsUser Experience Design Heuristics
User Experience Design HeuristicsNathanael Boehm
 
CS101- Introduction to Computing- Lecture 24
CS101- Introduction to Computing- Lecture 24CS101- Introduction to Computing- Lecture 24
CS101- Introduction to Computing- Lecture 24Bilal Ahmed
 
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingAlgorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingTraian Rebedea
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristicskim.mens
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm designNahid Hasan
 

Andere mochten auch (10)

I Realize Lean Startup Hack-nov2010
I Realize Lean Startup Hack-nov2010I Realize Lean Startup Hack-nov2010
I Realize Lean Startup Hack-nov2010
 
Heuristics 101: Understanding and Applying Design Principles
Heuristics 101: Understanding and Applying Design PrinciplesHeuristics 101: Understanding and Applying Design Principles
Heuristics 101: Understanding and Applying Design Principles
 
Towards the Design of Heuristics by Means of Self-Assembly
Towards the Design of Heuristics by Means of Self-AssemblyTowards the Design of Heuristics by Means of Self-Assembly
Towards the Design of Heuristics by Means of Self-Assembly
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design Presentation
 
User Experience Design Heuristics
User Experience Design HeuristicsUser Experience Design Heuristics
User Experience Design Heuristics
 
CS101- Introduction to Computing- Lecture 24
CS101- Introduction to Computing- Lecture 24CS101- Introduction to Computing- Lecture 24
CS101- Introduction to Computing- Lecture 24
 
Algorithm Design
Algorithm DesignAlgorithm Design
Algorithm Design
 
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingAlgorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristics
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 

Ähnlich wie 10 Object-Oriented Design Heuristics for Rubyists

Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean CodingMetin Ogurlu
 
Zend Framework And Doctrine
Zend Framework And DoctrineZend Framework And Doctrine
Zend Framework And Doctrineisaaczfoster
 
Most valuable software design principles
Most valuable software design principlesMost valuable software design principles
Most valuable software design principlesJeroen Hildering
 
Dealing with Obese Models
Dealing with Obese ModelsDealing with Obese Models
Dealing with Obese ModelsRyan Brunner
 
Object oriented thinking
Object oriented thinkingObject oriented thinking
Object oriented thinkingMinal Maniar
 
Break the-rules
Break the-rulesBreak the-rules
Break the-rulesGokul Nk
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
How to fix bug or defects in software
How to fix bug or defects in software How to fix bug or defects in software
How to fix bug or defects in software Rajasekar Subramanian
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - EncapsulationMichael Heron
 
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
 
Top 5 performance problems in .net applications application performance mon...
Top 5 performance problems in .net applications   application performance mon...Top 5 performance problems in .net applications   application performance mon...
Top 5 performance problems in .net applications application performance mon...KennaaTol
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfTobiasGoeschel
 
Advanced oop laws, principles, idioms
Advanced oop laws, principles, idiomsAdvanced oop laws, principles, idioms
Advanced oop laws, principles, idiomsClint Edmonson
 
Where i put my business logic - Greach 2014, Madrid, Spain
Where i put my business logic  - Greach 2014, Madrid, SpainWhere i put my business logic  - Greach 2014, Madrid, Spain
Where i put my business logic - Greach 2014, Madrid, SpainAntonio de la Torre Fernández
 
Rebecca parsons agile east
Rebecca parsons   agile eastRebecca parsons   agile east
Rebecca parsons agile eastKmanthei
 

Ähnlich wie 10 Object-Oriented Design Heuristics for Rubyists (20)

Bad Smells in Code
Bad Smells in CodeBad Smells in Code
Bad Smells in Code
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
Six of the Best
Six of the BestSix of the Best
Six of the Best
 
Zend Framework And Doctrine
Zend Framework And DoctrineZend Framework And Doctrine
Zend Framework And Doctrine
 
Most valuable software design principles
Most valuable software design principlesMost valuable software design principles
Most valuable software design principles
 
Dealing with Obese Models
Dealing with Obese ModelsDealing with Obese Models
Dealing with Obese Models
 
Object oriented thinking
Object oriented thinkingObject oriented thinking
Object oriented thinking
 
Break the-rules
Break the-rulesBreak the-rules
Break the-rules
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
How to fix bug or defects in software
How to fix bug or defects in software How to fix bug or defects in software
How to fix bug or defects in software
 
SAD05 - Encapsulation
SAD05 - EncapsulationSAD05 - Encapsulation
SAD05 - Encapsulation
 
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
 
Refactoring
RefactoringRefactoring
Refactoring
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Top 5 performance problems in .net applications application performance mon...
Top 5 performance problems in .net applications   application performance mon...Top 5 performance problems in .net applications   application performance mon...
Top 5 performance problems in .net applications application performance mon...
 
Workshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdfWorkshop - The Little Pattern That Could.pdf
Workshop - The Little Pattern That Could.pdf
 
Advanced oop laws, principles, idioms
Advanced oop laws, principles, idiomsAdvanced oop laws, principles, idioms
Advanced oop laws, principles, idioms
 
Where i put my business logic - Greach 2014, Madrid, Spain
Where i put my business logic  - Greach 2014, Madrid, SpainWhere i put my business logic  - Greach 2014, Madrid, Spain
Where i put my business logic - Greach 2014, Madrid, Spain
 
Clean Code
Clean CodeClean Code
Clean Code
 
Rebecca parsons agile east
Rebecca parsons   agile eastRebecca parsons   agile east
Rebecca parsons agile east
 

Kürzlich hochgeladen

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

10 Object-Oriented Design Heuristics for Rubyists

  • 1.
  • 2.
  • 3.
  • 4.
  • 5. You want to encapsulate at all times.
 
 This initializer is focused on initialization. Setters guard their respective attributes (e.g. in this case, legal values for gender and status). 
 Hide direct attribute access even within the class.
  • 6.
  • 7.
  • 8. Public API should be useful without having to view implementation details.
 
 If this is not the case, improve your method signatures. ! How often do you look at public API method implementations offered by Gems?
  • 9. Why do you people indent private and protected methods?
 
 When followed consistently by a team, developers then know indented code is likely the implementation details of a class.
  • 10. Modules and concerns seem convenient, but there are some cons.
 
 They require reviewing an out of view file to know the API. ! Spurious methods can enter into the API. ! Alternative: ! Consider class-based composition. !
  • 11.
  • 12. Needs no explanation. We’ve all done it.
  • 13.
  • 14. Export coupling. FeedingTube is coupled to a receiver role which is played by the SlaveHuman instance.
  • 15. Nil coupling. No coupling, but you better have two instances or your program is uninteresting. ! Or consider String or Math classes as better examples of nil coupling; the above example could be argued as coupled. :)
  • 16.
  • 17. Beware of methods on a class that seem to be using accessors or methods of another class and few of its own. ! You may be writing a method that belongs on that other class. ! Changes there may break you here.
  • 18.
  • 19. There could be some argument here if a SlaveHuman is really just a role that a Human plays. ! The decision hinges on new and different behavior. This model implies that the Human doesn’t digest food.
 
 This is not true in the real world, but our model need only apply to the problem domain.
  • 20.
  • 21. Services Really en vogue now. Extract it to a service! A service should mediate between classes only when it makes no sense for any one of them to do so themselves. Consider whether one class has authoritative knowledge before separating out to a service. Lots of services yield an anemic object model; classes are stripped of behavior they should own. Services are great, just be sure you’ve thought it through.
  • 22.
  • 23. Problem A room requires heat when its temperature is greater than 72 and occupied. ! How shall we code it?
  • 24. Often seen. LeakyRoom leaks its details to allow the GodFurnace to take on too much responsibility.
  • 25. Well-place responsibilities. Did it all start with discipline at the public API level?
  • 26.
  • 27. God Classes • There are two kinds of God classes: • One that performs services by orchestrating object collaborations. Less data, more methods. • One that contains data that others need. Fewer methods, lots of data.
  • 28.
  • 29. Sometimes the real world is the wrong thing to model after. ! In this case, the building is more authoritative on targeting and damage, so the messaging is flipped. ! The wonderful thing about O-O design is that you get to create your own world which abides by your laws of physics.
  • 30. Down the rabbit hole of Object thinking...
  • 32. Tank, we need more O-O KNOWLEDGE programs...
  • 34. DDD