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

More Related Content

PPT
08 refactoring
PPT
Stoop 422-naming idioms
PPT
9 - OOP - Smalltalk Classes (b)
PDF
Stoop 400-metaclass only
PPT
PPT
Stoop 433-chain
PPT
Stoop 414-smalltalk elementsofdesign
PPT
7 - OOP - OO Concepts
08 refactoring
Stoop 422-naming idioms
9 - OOP - Smalltalk Classes (b)
Stoop 400-metaclass only
Stoop 433-chain
Stoop 414-smalltalk elementsofdesign
7 - OOP - OO Concepts

Viewers also liked (20)

PPT
11 - OOP - Numbers
PPT
12 virtualmachine
PPT
Stoop ed-frameworks
PPT
PPT
Stoop ed-some principles
PPT
Double Dispatch
PPT
14 - Exceptions
PPT
12 - Conditions and Loops
PPT
Stoop 436-strategy
PPT
5 - OOP - Smalltalk in a Nutshell (c)
PPT
PPT
Stoop 413-abstract classes
PPT
03 standardclasses
PPT
Stoop ed-inheritance composition
PPT
Debugging VisualWorks
PPT
Stoop ed-class forreuse
PPT
Stoop 434-composite
PDF
Stoop 415-design points
PPT
8 - OOP - Smalltalk Model
PPT
Stoop ed-dual interface
11 - OOP - Numbers
12 virtualmachine
Stoop ed-frameworks
Stoop ed-some principles
Double Dispatch
14 - Exceptions
12 - Conditions and Loops
Stoop 436-strategy
5 - OOP - Smalltalk in a Nutshell (c)
Stoop 413-abstract classes
03 standardclasses
Stoop ed-inheritance composition
Debugging VisualWorks
Stoop ed-class forreuse
Stoop 434-composite
Stoop 415-design points
8 - OOP - Smalltalk Model
Stoop ed-dual interface
Ad

Similar to Stoop sed-smells (20)

PPT
Stoop 421-design heuristics
PPT
Stoop 423-some designpatterns
PPT
Stoop 423-smalltalk idioms
PDF
Software Architecture: Principles, Patterns and Practices
PPTX
Clean code presentation
PDF
20080115 04 - La qualimétrie pour comprendre et appréhender les SI
PPT
Stoop 440-adaptor
PPT
PPTX
Introduction to Design Patterns
PPTX
Design pattern and their application
PPTX
Clean Code Part III - Craftsmanship at SoCal Code Camp
PDF
PPTX
Effective Java
PDF
Ducasse's Maintenance Expertise
PDF
Objects First With Java A Practical Introduction Using Bluej 1st Edition Davi...
PPTX
Software Patterns
PPT
10-design-patterns1.ppt.software engineering
PPT
Stoop 450-s unit
PDF
The maze of Design Patterns & SOLID Principles
Stoop 421-design heuristics
Stoop 423-some designpatterns
Stoop 423-smalltalk idioms
Software Architecture: Principles, Patterns and Practices
Clean code presentation
20080115 04 - La qualimétrie pour comprendre et appréhender les SI
Stoop 440-adaptor
Introduction to Design Patterns
Design pattern and their application
Clean Code Part III - Craftsmanship at SoCal Code Camp
Effective Java
Ducasse's Maintenance Expertise
Objects First With Java A Practical Introduction Using Bluej 1st Edition Davi...
Software Patterns
10-design-patterns1.ppt.software engineering
Stoop 450-s unit
The maze of Design Patterns & SOLID Principles
Ad

More from The World of Smalltalk (17)

PDF
05 seaside canvas
PPT
PPT
10 reflection
PPT
09 metaclasses
PPT
07 bestpractice
PPT
PPT
Stoop sed-sharing ornot
PPT
Stoop sed-class initialization
PPT
Stoop sed-class initialization
PPT
Stoop metaclasses
PPT
Stoop ed-unit ofreuse
PPT
Stoop ed-subtyping subclassing
PPT
Stoop 439-decorator
05 seaside canvas
10 reflection
09 metaclasses
07 bestpractice
Stoop sed-sharing ornot
Stoop sed-class initialization
Stoop sed-class initialization
Stoop metaclasses
Stoop ed-unit ofreuse
Stoop ed-subtyping subclassing
Stoop 439-decorator

Recently uploaded (20)

PPTX
1. Introduction to Computer Programming.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Approach and Philosophy of On baking technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Mushroom cultivation and it's methods.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
August Patch Tuesday
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
A Presentation on Artificial Intelligence
1. Introduction to Computer Programming.pptx
Spectroscopy.pptx food analysis technology
Approach and Philosophy of On baking technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TLE Review Electricity (Electricity).pptx
Tartificialntelligence_presentation.pptx
Encapsulation theory and applications.pdf
Mushroom cultivation and it's methods.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cloud_computing_Infrastucture_as_cloud_p
gpt5_lecture_notes_comprehensive_20250812015547.pdf
August Patch Tuesday
Advanced methodologies resolving dimensionality complications for autism neur...
Programs and apps: productivity, graphics, security and other tools
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Digital-Transformation-Roadmap-for-Companies.pptx
Machine learning based COVID-19 study performance prediction
Univ-Connecticut-ChatGPT-Presentaion.pdf
A Presentation on Artificial Intelligence

Stoop sed-smells

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse [email protected] 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