SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Stéphane Ducasse 1
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
Elements of Design -
Simple Smells
Simple Smells
S.Ducasse 2
A Simple Case...
Introduce parametrization
Avoid recompilation
S.Ducasse 3
Parametrization Advantages
DialectStream>>initializeST80ColorTable
"Initialize the colors that characterize the ST80 dialect"
ST80ColorTable := IdentityDictionary new.
#((temporaryVariable blue italic)
(methodArgument blue normal)
…
(setOrReturn black bold)) do:
[:aTriplet |
ST80ColorTable at: aTriplet first put: aTriplet allButFirst]
Problems:
Color tables hardcoded in method
Changes Require compilation
Client responsible of initialize invocation
No run-time changes
S.Ducasse 4
One Step
DialectStream>>initializeST80ColorTable
ST80ColorTable := IdentityDictionary new.
self defaultDescription do:
[:aTriplet |
ST80ColorTable at: aTriplet first put: aTriplet allButFirst]
DialectStream>>defaultDescription
^ #((temporaryVariable blue italic)
(methodArgument blue normal)
…
(setOrReturn black bold))
Still requires subclassing and recompilation
S.Ducasse 5
Composition-based Solution
DialectStream>>initializeST80ColorTableWith: anArray
ST80ColorTable := IdentityDictionary new.
anArray
do: [:aTriplet | ST80ColorTable at: aTriplet first
put: aTriplet allButFirst].
self initialize
•In a Client
DialectStream initializeST80ColorTableWith:
#(#(#temporaryVariable #blue #normal) …
#(#prefixKeyword #veryDarkGray #bold)
#(#setOrReturn #red #bold) )
S.Ducasse 6
Good Coding Practices
Good coding practices
promote good design
Encapsulation
Level of decomposition
Factoring constants
S.Ducasse 7
Be lazy and be private
Never do the job that you can delegate to another
one
Never let someone else plays with your private data
The Object Manifesto
S.Ducasse 8
The Programmer Manifesto
Say something only once
Don’t ask, tell!
S.Ducasse 9
Designing Classes for Reuse
Complete interface
Responsibility of the instance creation
Loose coupling between classes
Methods are units of reuse (self send)
Use polymorphism as much as possible to avoid type
checking
Behavior up and state down
Use correct names for class
Use correct names for methods
S.Ducasse 10
Behavior up State down
Abstract class
Concrete subclasses
S.Ducasse 11
Say once and only once
No duplicated magic number
Extract method
Remove duplicated code
S.Ducasse 12
Factorize Magic Numbers
Ideally you should be able to change your constants
without having any impact on the code!
For that
define a constant only once via accessor
provide testing method (hasNextNode)
default value using the constant accessor
S.Ducasse 13
Factoring Out Constants
We want to encapsulate the way “no next node” is
coded. Instead of writing:
Node>>nextNode
^ nextNode
NodeClient>>transmitTo: aNode
aNode nextNode = ‘no next node’
...
S.Ducasse 14
Factoring Out Constants
Write:
NodeClient>>transmitTo: aNode
aNode hasNextNode
....
Node>>hasNextNode
^ (self nextNode = self class noNextNode) not
Node class>>noNextNode
^ ‘no next node’
S.Ducasse 15
Default value between class and instance
If we want to encapsulate the way “no next node” is
coded and shared this knowledge between class and
instances.
Instead of writing:
aNode nextNode isNil not
Write:
Node>>hasNextNode
^ self nextNode = self noNextNode
Node>>noNextNode
^self class noNextNode
Node class>>noNextNode
^ #noNode
S.Ducasse 16
Initializing without Duplicating
Node>>initialize
accessType := ‘local’
...
Node>>isLocal
^ accessType = ‘local’
It’s better to write
Node>>initialize
accessType := self localAccessType
Node>>isLocal
^ accessType = self localAccessType
Node>>localAccessType
S.Ducasse 17
Good Signs of OOThinking
Short methods
No dense methods
No super-intelligent objects
No manager objects
Objects with clear responsibilities
State the purpose of the class in one sentence
Not too many instance variables
S.Ducasse 18
How do you divide a program into methods?
Messages take time
Flow of control is difficult with small methods
But:
Reading is improved
Performance tuning is simpler (Cache...)
Easier to maintain / inheritance impact
Composed Methods
S.Ducasse 19
Composed Methods
Divide your program into methods that perform one
identifiable task. Keep all of the operations in a
method at the same level of abstraction.
Controller>>controlActivity
self controlInitialize.
self controlLoop.
self controlTerminate
S.Ducasse 20
Do you See the Problem?
initializeToStandAlone
super initializeToStandAlone.
self borderWidth: 2.
self borderColor: Color black.
self color: Color blue muchLighter.
self extent: self class defaultTileSize * (self columnNumber @ self rowNumber).
self initializeBots.
self running.
area := Matrix rows: self rowNumber columns: self columnNumber.
area indicesDo: [:row :column | area at: row at: column
put: OrderedCollection new].
self fillWorldWithGround.
self firstArea.
self installCurrentArea
S.Ducasse 21
Do you See the Problem?
initializeToStandAlone
super initializeToStandAlone.
self initializeBoardLayout.
self initializeBots.
self running.
self initializeArea.
self fillWorldWithGround.
self firstArea.
self installCurrentArea
S.Ducasse 22
With code reuse…
initializeArea
area := self matrixClass
rows: self rowNumber
columns: self columnNumber.
area indicesDo: [:row :column | area
at: row
at: column
put: OrderedCollection new]
initializeArea can be invoke several times
S.Ducasse 23
About Methods
• Avoid long methods
• A method: one task
• Avoid duplicated code
• Reuse Logic
S.Ducasse 24
Class Design
S.Ducasse 25
Behavior Up and State Down
Define classes by behavior, not state
Implement behavior with abstract state: if you need state
do it indirectly via messages.
Do not reference the state variables directly
Identify message layers: implement class’s behavior
through a small set of kernel method
S.Ducasse 26
Example
Collection>>removeAll: aCollection
aCollection do: [:each | self remove: each]
^ aCollection
Collection>>remove: oldObject
self remove: oldObject ifAbsent: [self notFoundError]
Collection>>remove: anObject ifAbsent:
anExceptionBlock
self subclassResponsibility
S.Ducasse 27
Behavior-Defined Class
When creating a new class, define its public protocol and
specify its behavior without regard to data structure
(such as instance variables, class variables, and so on).
For example:
Rectangle
Protocol:
area
intersects:
contains:
perimeter
width
height
insetBy:
S.Ducasse 28
Implement Behavior with Abstract State
If state is needed to complete the implementation
Identify the state by defining a message that returns that
state instead of defining a variable.
For example, use
Circle>>area
^self radius squared * self pi
not
Circle>>area
^radius squared * pi.
S.Ducasse 29
Identify Message Layers
How can methods be factored to make the class both
efficient and simple to subclass?
Identify a small subset of the abstract state and behavior
methods which all other methods can rely on as kernel
methods.
Circle>>radius
Circle>>pi
Circle>>center
Circle>>diameter
^self radius * 2
Circle>>area
^self radius squared * self pi

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)
 
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)
 
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)
 
02 basics
02 basics02 basics
02 basics
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
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
 
04 idioms
04 idioms04 idioms
04 idioms
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
Swift Programming - Part 2
Swift Programming - Part 2Swift Programming - Part 2
Swift Programming - Part 2
 
10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)
 
2013 lecture-02-syntax shortnewcut
2013 lecture-02-syntax shortnewcut2013 lecture-02-syntax shortnewcut
2013 lecture-02-syntax shortnewcut
 
Swift Bengaluru Meetup slides
Swift Bengaluru Meetup slidesSwift Bengaluru Meetup slides
Swift Bengaluru Meetup slides
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 

Andere mochten auch (20)

Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop 439-decorator
Stoop 439-decoratorStoop 439-decorator
Stoop 439-decorator
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 
Stoop 436-strategy
Stoop 436-strategyStoop 436-strategy
Stoop 436-strategy
 
Stoop 422-naming idioms
Stoop 422-naming idiomsStoop 422-naming idioms
Stoop 422-naming idioms
 
Stoop 390-instruction stream
Stoop 390-instruction streamStoop 390-instruction stream
Stoop 390-instruction stream
 
10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
05 seaside
05 seaside05 seaside
05 seaside
 
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
 
Stoop 413-abstract classes
Stoop 413-abstract classesStoop 413-abstract classes
Stoop 413-abstract classes
 
06 debugging
06 debugging06 debugging
06 debugging
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model
 
10 reflection
10 reflection10 reflection
10 reflection
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 

Ähnlich wie Stoop ed-class forreuse

two dimensional array
two dimensional array two dimensional array
two dimensional array Tariq Aziz
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode CompilerDonal Fellows
 
CUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : NotesCUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : NotesSubhajit Sahu
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkCHOOSE
 
Advanced programming topics asma
Advanced programming topics asmaAdvanced programming topics asma
Advanced programming topics asmaAbdullahJana
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたAkira Maruoka
 
Rechecking SharpDevelop: Any New Bugs?
Rechecking SharpDevelop: Any New Bugs?Rechecking SharpDevelop: Any New Bugs?
Rechecking SharpDevelop: Any New Bugs?PVS-Studio
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceJesse Vincent
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NETDoommaker
 

Ähnlich wie Stoop ed-class forreuse (20)

9 - OOP - Smalltalk Classes (a)
9 - OOP - Smalltalk Classes (a)9 - OOP - Smalltalk Classes (a)
9 - OOP - Smalltalk Classes (a)
 
9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)
 
two dimensional array
two dimensional array two dimensional array
two dimensional array
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
 
CUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : NotesCUDA by Example : Thread Cooperation : Notes
CUDA by Example : Thread Cooperation : Notes
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
 
Advanced programming topics asma
Advanced programming topics asmaAdvanced programming topics asma
Advanced programming topics asma
 
algorithm
algorithmalgorithm
algorithm
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Rechecking SharpDevelop: Any New Bugs?
Rechecking SharpDevelop: Any New Bugs?Rechecking SharpDevelop: Any New Bugs?
Rechecking SharpDevelop: Any New Bugs?
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Java Basics 1.pptx
Java Basics 1.pptxJava Basics 1.pptx
Java Basics 1.pptx
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
What’s new in .NET
What’s new in .NETWhat’s new in .NET
What’s new in .NET
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
Vectors Intro.ppt
Vectors Intro.pptVectors Intro.ppt
Vectors Intro.ppt
 
Stoop 431-visitor
Stoop 431-visitorStoop 431-visitor
Stoop 431-visitor
 

Mehr von The World of Smalltalk (10)

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
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
01 intro
01 intro01 intro
01 intro
 
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-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 

Stoop ed-class forreuse

  • 1. Stéphane Ducasse 1 Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Elements of Design - Simple Smells Simple Smells
  • 2. S.Ducasse 2 A Simple Case... Introduce parametrization Avoid recompilation
  • 3. S.Ducasse 3 Parametrization Advantages DialectStream>>initializeST80ColorTable "Initialize the colors that characterize the ST80 dialect" ST80ColorTable := IdentityDictionary new. #((temporaryVariable blue italic) (methodArgument blue normal) … (setOrReturn black bold)) do: [:aTriplet | ST80ColorTable at: aTriplet first put: aTriplet allButFirst] Problems: Color tables hardcoded in method Changes Require compilation Client responsible of initialize invocation No run-time changes
  • 4. S.Ducasse 4 One Step DialectStream>>initializeST80ColorTable ST80ColorTable := IdentityDictionary new. self defaultDescription do: [:aTriplet | ST80ColorTable at: aTriplet first put: aTriplet allButFirst] DialectStream>>defaultDescription ^ #((temporaryVariable blue italic) (methodArgument blue normal) … (setOrReturn black bold)) Still requires subclassing and recompilation
  • 5. S.Ducasse 5 Composition-based Solution DialectStream>>initializeST80ColorTableWith: anArray ST80ColorTable := IdentityDictionary new. anArray do: [:aTriplet | ST80ColorTable at: aTriplet first put: aTriplet allButFirst]. self initialize •In a Client DialectStream initializeST80ColorTableWith: #(#(#temporaryVariable #blue #normal) … #(#prefixKeyword #veryDarkGray #bold) #(#setOrReturn #red #bold) )
  • 6. S.Ducasse 6 Good Coding Practices Good coding practices promote good design Encapsulation Level of decomposition Factoring constants
  • 7. S.Ducasse 7 Be lazy and be private Never do the job that you can delegate to another one Never let someone else plays with your private data The Object Manifesto
  • 8. S.Ducasse 8 The Programmer Manifesto Say something only once Don’t ask, tell!
  • 9. S.Ducasse 9 Designing Classes for Reuse Complete interface Responsibility of the instance creation Loose coupling between classes Methods are units of reuse (self send) Use polymorphism as much as possible to avoid type checking Behavior up and state down Use correct names for class Use correct names for methods
  • 10. S.Ducasse 10 Behavior up State down Abstract class Concrete subclasses
  • 11. S.Ducasse 11 Say once and only once No duplicated magic number Extract method Remove duplicated code
  • 12. S.Ducasse 12 Factorize Magic Numbers Ideally you should be able to change your constants without having any impact on the code! For that define a constant only once via accessor provide testing method (hasNextNode) default value using the constant accessor
  • 13. S.Ducasse 13 Factoring Out Constants We want to encapsulate the way “no next node” is coded. Instead of writing: Node>>nextNode ^ nextNode NodeClient>>transmitTo: aNode aNode nextNode = ‘no next node’ ...
  • 14. S.Ducasse 14 Factoring Out Constants Write: NodeClient>>transmitTo: aNode aNode hasNextNode .... Node>>hasNextNode ^ (self nextNode = self class noNextNode) not Node class>>noNextNode ^ ‘no next node’
  • 15. S.Ducasse 15 Default value between class and instance If we want to encapsulate the way “no next node” is coded and shared this knowledge between class and instances. Instead of writing: aNode nextNode isNil not Write: Node>>hasNextNode ^ self nextNode = self noNextNode Node>>noNextNode ^self class noNextNode Node class>>noNextNode ^ #noNode
  • 16. S.Ducasse 16 Initializing without Duplicating Node>>initialize accessType := ‘local’ ... Node>>isLocal ^ accessType = ‘local’ It’s better to write Node>>initialize accessType := self localAccessType Node>>isLocal ^ accessType = self localAccessType Node>>localAccessType
  • 17. S.Ducasse 17 Good Signs of OOThinking Short methods No dense methods No super-intelligent objects No manager objects Objects with clear responsibilities State the purpose of the class in one sentence Not too many instance variables
  • 18. S.Ducasse 18 How do you divide a program into methods? Messages take time Flow of control is difficult with small methods But: Reading is improved Performance tuning is simpler (Cache...) Easier to maintain / inheritance impact Composed Methods
  • 19. S.Ducasse 19 Composed Methods Divide your program into methods that perform one identifiable task. Keep all of the operations in a method at the same level of abstraction. Controller>>controlActivity self controlInitialize. self controlLoop. self controlTerminate
  • 20. S.Ducasse 20 Do you See the Problem? initializeToStandAlone super initializeToStandAlone. self borderWidth: 2. self borderColor: Color black. self color: Color blue muchLighter. self extent: self class defaultTileSize * (self columnNumber @ self rowNumber). self initializeBots. self running. area := Matrix rows: self rowNumber columns: self columnNumber. area indicesDo: [:row :column | area at: row at: column put: OrderedCollection new]. self fillWorldWithGround. self firstArea. self installCurrentArea
  • 21. S.Ducasse 21 Do you See the Problem? initializeToStandAlone super initializeToStandAlone. self initializeBoardLayout. self initializeBots. self running. self initializeArea. self fillWorldWithGround. self firstArea. self installCurrentArea
  • 22. S.Ducasse 22 With code reuse… initializeArea area := self matrixClass rows: self rowNumber columns: self columnNumber. area indicesDo: [:row :column | area at: row at: column put: OrderedCollection new] initializeArea can be invoke several times
  • 23. S.Ducasse 23 About Methods • Avoid long methods • A method: one task • Avoid duplicated code • Reuse Logic
  • 25. S.Ducasse 25 Behavior Up and State Down Define classes by behavior, not state Implement behavior with abstract state: if you need state do it indirectly via messages. Do not reference the state variables directly Identify message layers: implement class’s behavior through a small set of kernel method
  • 26. S.Ducasse 26 Example Collection>>removeAll: aCollection aCollection do: [:each | self remove: each] ^ aCollection Collection>>remove: oldObject self remove: oldObject ifAbsent: [self notFoundError] Collection>>remove: anObject ifAbsent: anExceptionBlock self subclassResponsibility
  • 27. S.Ducasse 27 Behavior-Defined Class When creating a new class, define its public protocol and specify its behavior without regard to data structure (such as instance variables, class variables, and so on). For example: Rectangle Protocol: area intersects: contains: perimeter width height insetBy:
  • 28. S.Ducasse 28 Implement Behavior with Abstract State If state is needed to complete the implementation Identify the state by defining a message that returns that state instead of defining a variable. For example, use Circle>>area ^self radius squared * self pi not Circle>>area ^radius squared * pi.
  • 29. S.Ducasse 29 Identify Message Layers How can methods be factored to make the class both efficient and simple to subclass? Identify a small subset of the abstract state and behavior methods which all other methods can rely on as kernel methods. Circle>>radius Circle>>pi Circle>>center Circle>>diameter ^self radius * 2 Circle>>area ^self radius squared * self pi