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 ed-subtyping subclassing
PPT
Stoop 423-some designpatterns
PPT
4 - OOP - Taste of Smalltalk (Tamagoshi)
PDF
Robots in Swift
PPT
4 - OOP - Taste of Smalltalk (Squeak)
PDF
Thinking In Swift
PPT
Stoop 432-singleton
PPT
4 - OOP - Taste of Smalltalk (VisualWorks)
PPT
PDF
Pharo - I have a dream @ Smalltalks Conference 2009
PPT
The Theory Of The Dom
PPT
5 - OOP - Smalltalk in a Nutshell (b)
PPT
Stoop 416-lsp
PDF
Javascript Best Practices
PPT
CLR Exception Handing And Memory Management
PPTX
Dependency Injection and Autofac
PDF
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyone
PDF
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian Heigl
PPT
9 - OOP - Smalltalk Classes (c)
PPTX
Falling off the shoulders of giants
Stoop ed-subtyping subclassing
Stoop 423-some designpatterns
4 - OOP - Taste of Smalltalk (Tamagoshi)
Robots in Swift
4 - OOP - Taste of Smalltalk (Squeak)
Thinking In Swift
Stoop 432-singleton
4 - OOP - Taste of Smalltalk (VisualWorks)
Pharo - I have a dream @ Smalltalks Conference 2009
The Theory Of The Dom
5 - OOP - Smalltalk in a Nutshell (b)
Stoop 416-lsp
Javascript Best Practices
CLR Exception Handing And Memory Management
Dependency Injection and Autofac
OSDC 2017 - Florian Heigl - Experiences with rudder, is it really for everyone
OSDC 2017 | Experiences with Rudder, is it really for everyone? by Florian Heigl
9 - OOP - Smalltalk Classes (c)
Falling off the shoulders of giants
Ad

More from The World of Smalltalk (18)

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 450-s unit
PPT
Stoop 440-adaptor
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 450-s unit
Stoop 440-adaptor
Stoop 439-decorator

Recently uploaded (20)

PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
project resource management chapter-09.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
STKI Israel Market Study 2025 version august
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPT
What is a Computer? Input Devices /output devices
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Architecture types and enterprise applications.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Module 1.ppt Iot fundamentals and Architecture
NewMind AI Weekly Chronicles - August'25-Week II
OMC Textile Division Presentation 2021.pptx
project resource management chapter-09.pdf
Modernising the Digital Integration Hub
Assigned Numbers - 2025 - Bluetooth® Document
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Developing a website for English-speaking practice to English as a foreign la...
Programs and apps: productivity, graphics, security and other tools
Univ-Connecticut-ChatGPT-Presentaion.pdf
STKI Israel Market Study 2025 version august
gpt5_lecture_notes_comprehensive_20250812015547.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
What is a Computer? Input Devices /output devices
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Group 1 Presentation -Planning and Decision Making .pptx
WOOl fibre morphology and structure.pdf for textiles
Getting started with AI Agents and Multi-Agent Systems
Architecture types and enterprise applications.pdf

Stoop sed-smells

  • 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