SlideShare ist ein Scribd-Unternehmen logo
1 von 13
S.Ducasse 1
QuickTimeℱ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.iam.unibe.ch/~ducasse/
Elements of Design -
Simple Smells
Simple Smells
S.Ducasse 2
Basic Design Mistakes
S.Ducasse 3
A Class should have
Class Person {
String getName();
void setName(String name);
int getAge();
void setAge(int age);
Car getCar();
void setCar(Car car);
}
What do we see ?
A class should have one main responsibility and some
behavior not just holding state
Minimal access to its data!
S.Ducasse 4
Confusing
Class City extends Place { 
 }
Class Jerusalem extends City implements Capital { 
 }
Class TelAviv extends City { 
 }
What is wrong here?
Confusing inheritance and instantiation
Too much inheritance?
S.Ducasse 5
Do not expose implementation
S.Ducasse 6
Do not overuse conversions
nodes asSet
removes all the duplicated nodes (if node knows how to
compare). But a systematic use of asSet to protect yourself
from duplicate is not good
nodes asSet asOrderedCollection
returns an ordered collection after removing duplicates
Look for the real source of duplication if you do not want
it!
S.Ducasse 7
Hiding missing information
Dictionary>>at: aKey
This raises an error if the key is not found
Dictionary>>at: aKey ifAbsent: aBlock
Allows one to specify action aBlock to be done when the
key does not exist.
Do not overuse it:
nodes at: nodeId ifAbsent:[ ]
This is bad because at least we should know that the
nodeId was missing
S.Ducasse 8
Avoid returning nil
Avoid to return special results as nil
messages := self fetchMessages.
messages isNil
  ifFalse: [ messages dispatchFrom: self ]
What if we would simply return an empty collection in
fetchMessages instead of nil?
Less conditional and ugly tests!!
S.Ducasse 9
Objects not strings!
‱ Strings are dead objects
‱ You can only concatenate strings
‱ Use objects not their textual representation
S.Ducasse 10
Objects not tuples!
‱ spec first
‱ spec second
‱ spec third
‱ spec action
‱ spec selector
‱ spec menuItem
‱ And add a printing
‱ aSpec(‘open’, #openBrowser,‘open (O)’)
S.Ducasse 11
Tell, Don’t Ask
‱ no condition and case based on the receiver type
‱ Use polymorphism as much as possible to avoid type
checking
S.Ducasse 12
Tell, Don’t Ask!
MyWindow>>displayObject: aGrObject
aGrObject displayOn: self
‱And not:
MyWindow>>displayObject: aGrObject
aGrObject isSquare ifTrue: [
]
aGrObject isCircle ifTrue: [
]


S.Ducasse 13
Don’t violate encapsulation
No overuse of accessors
Encapsulation principle: minimize data representation
dependencies
Offer complete interface

Weitere Àhnliche Inhalte

Andere mochten auch (20)

11 - OOP - Numbers
11 - OOP - Numbers11 - OOP - Numbers
11 - OOP - Numbers
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
 
14 - Exceptions
14 - Exceptions14 - Exceptions
14 - Exceptions
 
12 - Conditions and Loops
12 - Conditions and Loops12 - Conditions and Loops
12 - Conditions and Loops
 
Stoop 436-strategy
Stoop 436-strategyStoop 436-strategy
Stoop 436-strategy
 
5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)
 
15 - Streams
15 - Streams15 - Streams
15 - Streams
 
Stoop 413-abstract classes
Stoop 413-abstract classesStoop 413-abstract classes
Stoop 413-abstract classes
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Debugging VisualWorks
Debugging VisualWorksDebugging VisualWorks
Debugging VisualWorks
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 
Stoop 434-composite
Stoop 434-compositeStoop 434-composite
Stoop 434-composite
 
Stoop 415-design points
Stoop 415-design pointsStoop 415-design points
Stoop 415-design points
 
8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 

Ähnlich wie Simple Design Mistakes to Avoid

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
 
Robots in Swift
Robots in SwiftRobots in Swift
Robots in SwiftJanie Clayton
 
4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)The World of Smalltalk
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In SwiftJanie Clayton
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)The World of Smalltalk
 
Pharo - I have a dream @ Smalltalks Conference 2009
Pharo -  I have a dream @ Smalltalks Conference 2009Pharo -  I have a dream @ Smalltalks Conference 2009
Pharo - I have a dream @ Smalltalks Conference 2009Pharo
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)The World of Smalltalk
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best PracticesChristian Heilmann
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementShiny Zhu
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofacmeghantaylor
 
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian Heigl
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian HeiglOSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian Heigl
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian HeiglNETWAYS
 
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyone
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyoneOSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyone
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyoneNETWAYS
 
Falling off the shoulders of giants
Falling off the shoulders of giantsFalling off the shoulders of giants
Falling off the shoulders of giantsMike Wessling
 

Ähnlich wie Simple Design Mistakes to Avoid (20)

Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)
 
Robots in Swift
Robots in SwiftRobots in Swift
Robots in Swift
 
4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
Stoop 432-singleton
Stoop 432-singletonStoop 432-singleton
Stoop 432-singleton
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Pharo - I have a dream @ Smalltalks Conference 2009
Pharo -  I have a dream @ Smalltalks Conference 2009Pharo -  I have a dream @ Smalltalks Conference 2009
Pharo - I have a dream @ Smalltalks Conference 2009
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory Management
 
Dependency Injection and Autofac
Dependency Injection and AutofacDependency Injection and Autofac
Dependency Injection and Autofac
 
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian Heigl
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian HeiglOSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian Heigl
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian Heigl
 
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyone
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyoneOSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyone
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyone
 
9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)
 
Falling off the shoulders of giants
Falling off the shoulders of giantsFalling off the shoulders of giants
Falling off the shoulders of giants
 

Mehr von The World of Smalltalk (18)

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
 
10 reflection
10 reflection10 reflection
10 reflection
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
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 metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
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
 
Stoop 439-decorator
Stoop 439-decoratorStoop 439-decorator
Stoop 439-decorator
 

KĂŒrzlich hochgeladen

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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...gurkirankumar98700
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

KĂŒrzlich hochgeladen (20)

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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Simple Design Mistakes to Avoid

  • 1. S.Ducasse 1 QuickTimeℱ and aTIFF (Uncompressed) decompressorare needed to see this picture. StĂ©phane Ducasse Stephane.Ducasse@univ-savoie.fr http://www.iam.unibe.ch/~ducasse/ Elements of Design - Simple Smells Simple Smells
  • 3. S.Ducasse 3 A Class should have Class Person { String getName(); void setName(String name); int getAge(); void setAge(int age); Car getCar(); void setCar(Car car); } What do we see ? A class should have one main responsibility and some behavior not just holding state Minimal access to its data!
  • 4. S.Ducasse 4 Confusing Class City extends Place { 
 } Class Jerusalem extends City implements Capital { 
 } Class TelAviv extends City { 
 } What is wrong here? Confusing inheritance and instantiation Too much inheritance?
  • 5. S.Ducasse 5 Do not expose implementation
  • 6. S.Ducasse 6 Do not overuse conversions nodes asSet removes all the duplicated nodes (if node knows how to compare). But a systematic use of asSet to protect yourself from duplicate is not good nodes asSet asOrderedCollection returns an ordered collection after removing duplicates Look for the real source of duplication if you do not want it!
  • 7. S.Ducasse 7 Hiding missing information Dictionary>>at: aKey This raises an error if the key is not found Dictionary>>at: aKey ifAbsent: aBlock Allows one to specify action aBlock to be done when the key does not exist. Do not overuse it: nodes at: nodeId ifAbsent:[ ] This is bad because at least we should know that the nodeId was missing
  • 8. S.Ducasse 8 Avoid returning nil Avoid to return special results as nil messages := self fetchMessages. messages isNil   ifFalse: [ messages dispatchFrom: self ] What if we would simply return an empty collection in fetchMessages instead of nil? Less conditional and ugly tests!!
  • 9. S.Ducasse 9 Objects not strings! ‱ Strings are dead objects ‱ You can only concatenate strings ‱ Use objects not their textual representation
  • 10. S.Ducasse 10 Objects not tuples! ‱ spec first ‱ spec second ‱ spec third ‱ spec action ‱ spec selector ‱ spec menuItem ‱ And add a printing ‱ aSpec(‘open’, #openBrowser,‘open (O)’)
  • 11. S.Ducasse 11 Tell, Don’t Ask ‱ no condition and case based on the receiver type ‱ Use polymorphism as much as possible to avoid type checking
  • 12. S.Ducasse 12 Tell, Don’t Ask! MyWindow>>displayObject: aGrObject aGrObject displayOn: self ‱And not: MyWindow>>displayObject: aGrObject aGrObject isSquare ifTrue: [
] aGrObject isCircle ifTrue: [
] 

  • 13. S.Ducasse 13 Don’t violate encapsulation No overuse of accessors Encapsulation principle: minimize data representation dependencies Offer complete interface