SlideShare a Scribd company logo
1 of 31
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
Design Heuristics
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
Roadmap
• Inspired from Object-Oriented
• Design Heuristics by Arthur Riel
• Read the Heuristics…
• Find reasons why
• We will discuss them during the lectures
S.Ducasse 4
Different Relationships
• Uses
• Contains
• Specializes
S.Ducasse 5
Hidding Data
• All data should be hidden within its class
S.Ducasse 6
No Dependence on Clients
• Users of a class must be dependent on its public
interface, but a class should not be dependent on its
users
S.Ducasse 7
Class = one Clear Responsibility
• Minimize the number of messages in the protocol of a
class
S.Ducasse 8
Supporting Polymorphism
• Implement a minimal interface that all classes
understand
• To send the same message to different objects
• To be able to substitute them
• Remember:
• grObjects do: [:each | each translate: 10@10]
• Example: Object>>printString, Object>>copy…
S.Ducasse 9
Clear Public Interface
• Do not put implementations details such as common-
code private functions into the public interface of a
class
• Example:
• Private/protected in C++
• Private method categories in Smalltalk
• Do not clutter the public interface of a class with
items that clients are not able to use or are not
interested in using
S.Ducasse 10
Minimize Class Interdependencies
• A class should only use operations in the public
interface of another class or have nothing to do with
that class
S.Ducasse 11
Class = one Responsibility
• A class should capture one and only one key
abstraction
S.Ducasse 12
Strengthen Encapsulation
• Keep related data and behavior in one place
• Spin off non related information into another class
• => Move Data Close to Behavior
S.Ducasse 13
Object: a Cohesive Entity
• Most of the methods defined on a class should be
using most of the instance variables most of the time
S.Ducasse 14
Roles vs. Classes
• Be sure the abstractions you model are classes and
not the roles objects play
• Are mother and father classes or role of Person?
• No magic answer: Depend on the domain
• Do they have different behavior? So they are more
distinct classes
S.Ducasse 15
one Class = one Responsibility
• Distribute system intelligence horizontally as
uniformly as possible, i.e., the top-level classes in a
design should share the work
S.Ducasse 16
one Class = one Responsibility
• Do not create god classes/objects (classes that control
all other classes).
• Be very suspicious of class whose names contains
Driver, Manager, System, SubSystem.
S.Ducasse 17
Model and Interfaces
• Model should never be dependent on the interface
that represents it.The interface should be dependent
on the model
• What is happening if you want two different Uis for
the same model?
S.Ducasse 18
Basic Checks for God Class
• Beware of classes that have many accessor methods
defined in their public interface. May imply that data
and behavior is not being kept at the same place
• Beware of classes having methods that only operate
on a proper subset of the instance variables.
S.Ducasse 19
One Class: One Responsibility
• One responbility: coordinating and using other objects
• OrderedCollection maintains a list of objects sorted by
arrival order: two indexes and a list
• Class should not contain more objects than a
developper can fit in his short-term memory. (6 or 7 is
the average value)
S.Ducasse 20
Classes Evaluation
• Model the real world whenever possible
• Eliminate irrelevant classes
• Eliminate classes that are outside of the system
• A method is not a class. Be suspicious of any class
whose name is a verb or derived from a verb,
especially those that only one piece of meaningful
behavior
S.Ducasse 21
Minimizing Coupling between
Classes
• Minimize the number of classes with which another
class collaborates
• Minimize the number of messages sent between a
class and its collaborators
• Counter example:Visitor patterns
• Minimize the number of different messages sent
between a class and its collaborators
S.Ducasse 22
Use
S.Ducasse 23
About the Use Relationship
• When an object use another one it should get a
reference on it to interact with it
• Ways to get references
• (containment) instance variables of the class
• Passed has argument
• Ask to a third party object (mapping…)
• Create the object and interact with it
S.Ducasse 24
Containment and Uses
• If a class contains object of another class, then the
containing class should be sending messages to the
contained objects (the containment relationship
should always imply a uses relationships)
• A object may know what it contains but it should not
know who contains it.
S.Ducasse 25
Representing Semantics Constraints
• How do we represent possibilities or constraints
between classes?
• Appetizer, entrée, main dish…
• No peas and corn together…
• It is best to implement them in terms of class
definition but this may lead to class proliferation
• => implemented in the creation method
S.Ducasse 26
Objects define their logic
• When implementing semantic constraints in the
constructor of a class, place the constraint definition
as far down a containment hierarchy as the domain
allows
• => Objects should contain the semantic constraints
about themselves
S.Ducasse 27
Third party constraint holder
• If the logic of a constraint is volatile, then it is better
to represent it in a separate object
S.Ducasse 28
Classes - Subclasses
• Superclass should not know its subclasses
• Subclasses should not use directly data of superclasses
• If two or more classes have common data and
behavior, they should inherit from a common class that
captures those data and behavior
S.Ducasse 29
Controversial
• All abstract classes must be base classes
• All base classes should be abstract classes
• => Not true they can have default value method
S.Ducasse 30
Avoid Type Checks
• Explicit case analysis on the type of an objects is
usually an error.
• An object is responsible of deciding how to answer to
a message
• A client should send message and not discriminate
messages sent based on receiver type
S.Ducasse 31
Summary
Digest
Read code
Think about it
Be critic

More Related Content

Viewers also liked (20)

Stoop 437-proxy
Stoop 437-proxyStoop 437-proxy
Stoop 437-proxy
 
Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
 
Stoop 413-abstract classes
Stoop 413-abstract classesStoop 413-abstract classes
Stoop 413-abstract classes
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
12 - Conditions and Loops
12 - Conditions and Loops12 - Conditions and Loops
12 - Conditions and Loops
 
15 - Streams
15 - Streams15 - Streams
15 - Streams
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
Debugging VisualWorks
Debugging VisualWorksDebugging VisualWorks
Debugging VisualWorks
 
Stoop 422-naming idioms
Stoop 422-naming idiomsStoop 422-naming idioms
Stoop 422-naming idioms
 
Stoop 400 o-metaclassonly
Stoop 400 o-metaclassonlyStoop 400 o-metaclassonly
Stoop 400 o-metaclassonly
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Stoop 430-design patternsintro
Stoop 430-design patternsintroStoop 430-design patternsintro
Stoop 430-design patternsintro
 
Stoop 434-composite
Stoop 434-compositeStoop 434-composite
Stoop 434-composite
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 

Similar to Stoop 421-design heuristics

Uniform and Safe Metaclass Composition
Uniform and Safe Metaclass CompositionUniform and Safe Metaclass Composition
Uniform and Safe Metaclass CompositionESUG
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristicskim.mens
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Ganapathi M
 
Object oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented conceptsObject oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented conceptsVaibhav Khanna
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptBill Buchan
 
4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)The World of Smalltalk
 
09 abstract classesandinterfaces
09 abstract classesandinterfaces09 abstract classesandinterfaces
09 abstract classesandinterfacesAPU
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_febRaj Shah
 
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...DuraSpace
 
When & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsWhen & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsAlena Holligan
 
CIRTL Spring 2016 College Classroom Meeting 9: Transparency
CIRTL Spring 2016 College Classroom Meeting 9: TransparencyCIRTL Spring 2016 College Classroom Meeting 9: Transparency
CIRTL Spring 2016 College Classroom Meeting 9: TransparencyPeter Newbury
 

Similar to Stoop 421-design heuristics (20)

1 - OOP
1 - OOP1 - OOP
1 - OOP
 
7 - OOP - OO Concepts
7 - OOP - OO Concepts7 - OOP - OO Concepts
7 - OOP - OO Concepts
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Uniform and Safe Metaclass Composition
Uniform and Safe Metaclass CompositionUniform and Safe Metaclass Composition
Uniform and Safe Metaclass Composition
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Object-Oriented Design Heuristics
Object-Oriented Design HeuristicsObject-Oriented Design Heuristics
Object-Oriented Design Heuristics
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0
 
Object oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented conceptsObject oriented programming 3 object oriented concepts
Object oriented programming 3 object oriented concepts
 
Design patterns
Design patternsDesign patterns
Design patterns
 
10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
 
4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)
 
09 abstract classesandinterfaces
09 abstract classesandinterfaces09 abstract classesandinterfaces
09 abstract classesandinterfaces
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
 
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
10-15-13 “Metadata and Repository Services for Research Data Curation” Presen...
 
When & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traitsWhen & Why: Interfaces, abstract classes, traits
When & Why: Interfaces, abstract classes, traits
 
CIRTL Spring 2016 College Classroom Meeting 9: Transparency
CIRTL Spring 2016 College Classroom Meeting 9: TransparencyCIRTL Spring 2016 College Classroom Meeting 9: Transparency
CIRTL Spring 2016 College Classroom Meeting 9: Transparency
 

More from The World of Smalltalk (15)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
04 idioms
04 idioms04 idioms
04 idioms
 
02 basics
02 basics02 basics
02 basics
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 

Stoop 421-design heuristics

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse Stephane.Ducasse@univ-savoie.fr http://www.listic.univ-savoie.fr/~ducasse/ Design Heuristics
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 Roadmap • Inspired from Object-Oriented • Design Heuristics by Arthur Riel • Read the Heuristics… • Find reasons why • We will discuss them during the lectures
  • 4. S.Ducasse 4 Different Relationships • Uses • Contains • Specializes
  • 5. S.Ducasse 5 Hidding Data • All data should be hidden within its class
  • 6. S.Ducasse 6 No Dependence on Clients • Users of a class must be dependent on its public interface, but a class should not be dependent on its users
  • 7. S.Ducasse 7 Class = one Clear Responsibility • Minimize the number of messages in the protocol of a class
  • 8. S.Ducasse 8 Supporting Polymorphism • Implement a minimal interface that all classes understand • To send the same message to different objects • To be able to substitute them • Remember: • grObjects do: [:each | each translate: 10@10] • Example: Object>>printString, Object>>copy…
  • 9. S.Ducasse 9 Clear Public Interface • Do not put implementations details such as common- code private functions into the public interface of a class • Example: • Private/protected in C++ • Private method categories in Smalltalk • Do not clutter the public interface of a class with items that clients are not able to use or are not interested in using
  • 10. S.Ducasse 10 Minimize Class Interdependencies • A class should only use operations in the public interface of another class or have nothing to do with that class
  • 11. S.Ducasse 11 Class = one Responsibility • A class should capture one and only one key abstraction
  • 12. S.Ducasse 12 Strengthen Encapsulation • Keep related data and behavior in one place • Spin off non related information into another class • => Move Data Close to Behavior
  • 13. S.Ducasse 13 Object: a Cohesive Entity • Most of the methods defined on a class should be using most of the instance variables most of the time
  • 14. S.Ducasse 14 Roles vs. Classes • Be sure the abstractions you model are classes and not the roles objects play • Are mother and father classes or role of Person? • No magic answer: Depend on the domain • Do they have different behavior? So they are more distinct classes
  • 15. S.Ducasse 15 one Class = one Responsibility • Distribute system intelligence horizontally as uniformly as possible, i.e., the top-level classes in a design should share the work
  • 16. S.Ducasse 16 one Class = one Responsibility • Do not create god classes/objects (classes that control all other classes). • Be very suspicious of class whose names contains Driver, Manager, System, SubSystem.
  • 17. S.Ducasse 17 Model and Interfaces • Model should never be dependent on the interface that represents it.The interface should be dependent on the model • What is happening if you want two different Uis for the same model?
  • 18. S.Ducasse 18 Basic Checks for God Class • Beware of classes that have many accessor methods defined in their public interface. May imply that data and behavior is not being kept at the same place • Beware of classes having methods that only operate on a proper subset of the instance variables.
  • 19. S.Ducasse 19 One Class: One Responsibility • One responbility: coordinating and using other objects • OrderedCollection maintains a list of objects sorted by arrival order: two indexes and a list • Class should not contain more objects than a developper can fit in his short-term memory. (6 or 7 is the average value)
  • 20. S.Ducasse 20 Classes Evaluation • Model the real world whenever possible • Eliminate irrelevant classes • Eliminate classes that are outside of the system • A method is not a class. Be suspicious of any class whose name is a verb or derived from a verb, especially those that only one piece of meaningful behavior
  • 21. S.Ducasse 21 Minimizing Coupling between Classes • Minimize the number of classes with which another class collaborates • Minimize the number of messages sent between a class and its collaborators • Counter example:Visitor patterns • Minimize the number of different messages sent between a class and its collaborators
  • 23. S.Ducasse 23 About the Use Relationship • When an object use another one it should get a reference on it to interact with it • Ways to get references • (containment) instance variables of the class • Passed has argument • Ask to a third party object (mapping…) • Create the object and interact with it
  • 24. S.Ducasse 24 Containment and Uses • If a class contains object of another class, then the containing class should be sending messages to the contained objects (the containment relationship should always imply a uses relationships) • A object may know what it contains but it should not know who contains it.
  • 25. S.Ducasse 25 Representing Semantics Constraints • How do we represent possibilities or constraints between classes? • Appetizer, entrée, main dish… • No peas and corn together… • It is best to implement them in terms of class definition but this may lead to class proliferation • => implemented in the creation method
  • 26. S.Ducasse 26 Objects define their logic • When implementing semantic constraints in the constructor of a class, place the constraint definition as far down a containment hierarchy as the domain allows • => Objects should contain the semantic constraints about themselves
  • 27. S.Ducasse 27 Third party constraint holder • If the logic of a constraint is volatile, then it is better to represent it in a separate object
  • 28. S.Ducasse 28 Classes - Subclasses • Superclass should not know its subclasses • Subclasses should not use directly data of superclasses • If two or more classes have common data and behavior, they should inherit from a common class that captures those data and behavior
  • 29. S.Ducasse 29 Controversial • All abstract classes must be base classes • All base classes should be abstract classes • => Not true they can have default value method
  • 30. S.Ducasse 30 Avoid Type Checks • Explicit case analysis on the type of an objects is usually an error. • An object is responsible of deciding how to answer to a message • A client should send message and not discriminate messages sent based on receiver type