SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Stéphane Ducasse 1
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
Smalltalk in a Nutshell
S.Ducasse 2
Goals
Syntax in a Nutshell
OO Model in a Nutshell
S.Ducasse 3
Smalltalk OO Model
***Everything*** is an object
Only message passing
Only late binding
Instance variables are private to the object
Methods are public
Everything is a pointer
Garbage collector
Single inheritance between classes
Only message passing between objects
S.Ducasse 4
Complete Syntax on a PostCard
exampleWithNumber: x
“A method that illustrates every part of Smalltalk method syntax except primitives. It
has unary, binary, and key word messages, declares arguments and temporaries (but
not block temporaries), accesses a global variable (but not and instance variable), uses
literals (array, character, symbol, string, integer, float), uses the pseudo variable true
false, nil, self, and super, and has sequence, assignment, return and cascade. It has both
zero argument and one argument blocks. It doesn’t do anything useful, though”
|y|
true & false not & (nil isNil) ifFalse: [self halt].
y := self size + super size.
#($a #a ‘a’ 1 1.0)
do: [:each | Transcript
show: (each class name);
show: (each printString);
show:‘ ‘].
^ x < y
S.Ducasse 5
Language Constructs
^ return
“ comments
# symbol or array
‘ string
[ ] block or byte array
. separator and not terminator (or namespace access inVW)
; cascade (sending several messages to the same instance)
| local or block variable
:= assignment
$ character
: end of selector name
e, r number exponent or radix
! file element separator
<primitive: ...> forVM primitive calls
S.Ducasse 6
Syntax
comment: “a comment”
character: $c $h $a $r $a $c $t $e $r $s $# $@
string: ‘a nice string’ ‘lulu’ ‘l’’idiot’
symbol: #mac #+
array: #(1 2 3 (1 3) $a 4)
byte array: #[1 2 3]
integer: 1, 2r101
real: 1.5, 6.03e-34,4, 2.4e7
float: 1/33
boolean: true, false
point: 10@120
Note that @ is not an element of the syntax, but just a message sent to a
number.This is the same for /, bitShift, ifTrue:, do: ...
S.Ducasse 7
Syntax in a Nutshell (II)
assigment: var := aValue
block: [:var ||tmp| expr...]
temporary variable: |tmp|
block variable: :var
unary message: receiver selector
binary message: receiver selector argument
keyword based: receiver keyword1: arg1 keyword2:
arg2...
cascade: message ; selector ...
separator: message . message
result: ^
parenthesis: (...)
S.Ducasse 8
NameOfSuperclass subclass: #NameOfClass
instanceVariableNames: 'instVarName1'
classVariableNames: 'classVarName1'
poolDictionaries: ''
category: 'LAN'
Class Definition in St-80
S.Ducasse 9
Method Definition
• Normally defined in a browser or (by directly invoking the
compiler)
• Methods are public
• Always return self
Node>>accept: thePacket
"If the packet is addressed to me, print it.
Else just behave like a normal node"
(thePacket isAddressedTo: self)
ifTrue: [self print: thePacket]
ifFalse: [super accept: thePacket]
S.Ducasse 10
• ‘1’,‘abc’
• Basic class creation messages are
new, new:,
basicNew, basicNew:
Monster new
• Class specific message creation (messages sent to classes)
Tomagoshi withHunger: 10
S.Ducasse 11
Messages and their Composition
Three kinds of messages
Unary: Node new
Binary: 1 + 2, 3@4
Keywords: aTomagoshi eat: #cooky furiously: true
Message Priority
(Msg) > unary > binary > keywords
Same Level from left to right
Example:
(10@0 extent: 10@100) bottomRight
s isNil ifTrue: [ self halt ]
S.Ducasse 12
• Anonymous method
• Passed as method argument or stored
• Functions
fct(x)= x*x+3, fct(2).
fct :=[:x| x * x + 3]. fct value: 2
Integer>>factorial
| tmp |
tmp:= 1.
2 to: self do: [:i| tmp := tmp * i]
#(1 2 3) do: [:each | Transcript show: each printString ; cr]
Blocks
S.Ducasse 13
Yes ifTrue: is sent to a boolean
Weather isRaining
ifTrue: [self takeMyUmbrella]
ifFalse: [self takeMySunglasses]
ifTrue:ifFalse is sent to an object: a boolean!
S.Ducasse 14
Yes a collection is iterating on itself
#(1 2 -4 -86)
do: [:each | Transcript show: each abs
printString ;cr ]
> 1
> 2
> 4
> 86
Yes we ask the collection object to perform the
loop on itself
S.Ducasse 15
Summary
Objects and Messages
Three kinds of messages
unary
binary
keywords
Block: a.k.a innerclass or closures or lambda
Unary>Binary>Keywords
S.Ducasse 16
Goals
Syntax in a Nutshell
OO Model in a Nutshell
S.Ducasse 17
Instance and Class
• Only one model
• Uniformly applied
• Classes are objects too
S.Ducasse 18
Lookup…Class + Inheritance
1
2
S.Ducasse 19
Classes are objects too
• Instance creation is just a message send to a ... Class
• Same method lookup than with any other objects
• a Class is the single instance of amanonymous class
• Point is the single instance of Point class
S.Ducasse 20
Class Parallel Inheritance
S.Ducasse 21
Lookup and Class Methods
1
2
1
2
Workstation withName: ‘BigMac’
aWorkstation
name
S.Ducasse 22
About the Buttons
S.Ducasse 23
Summary
- Everything is an object
- One single model
- Single inheritance
- Public methods
- Protected attributes
- Classes are simply objects too
- Class is instance of another class
- One unique method lookup
look in the class of the receiver

Weitere ähnliche Inhalte

Was ist angesagt?

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 SmalltalkSerge Stinckwich
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellMarcus Denker
 
Pharo: Objects at your Fingertips
Pharo: Objects at your FingertipsPharo: Objects at your Fingertips
Pharo: Objects at your FingertipsMarcus Denker
 
An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...Claudio Capobianco
 
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 pramode_ce
 

Was ist angesagt? (15)

Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
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
 
02 basics
02 basics02 basics
02 basics
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
 
Pharo: Syntax in a Nutshell
Pharo: Syntax in a NutshellPharo: Syntax in a Nutshell
Pharo: Syntax in a Nutshell
 
Pharo: Objects at your Fingertips
Pharo: Objects at your FingertipsPharo: Objects at your Fingertips
Pharo: Objects at your Fingertips
 
4 recursion details
4 recursion details4 recursion details
4 recursion details
 
Java Basic day-1
Java Basic day-1Java Basic day-1
Java Basic day-1
 
10 inheritance
10 inheritance10 inheritance
10 inheritance
 
An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...
 
Macros in nemerle
Macros in nemerleMacros in nemerle
Macros in nemerle
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 

Andere mochten auch (20)

Stoop 430-design patternsintro
Stoop 430-design patternsintroStoop 430-design patternsintro
Stoop 430-design patternsintro
 
9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)
 
Stoop 400-metaclass only
Stoop 400-metaclass onlyStoop 400-metaclass only
Stoop 400-metaclass only
 
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
 
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 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
7 - OOP - OO Concepts
7 - OOP - OO Concepts7 - OOP - OO Concepts
7 - OOP - OO Concepts
 
05 seaside
05 seaside05 seaside
05 seaside
 
10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
 
Double Dispatch
Double DispatchDouble Dispatch
Double Dispatch
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
Stoop 390-instruction stream
Stoop 390-instruction streamStoop 390-instruction stream
Stoop 390-instruction stream
 
01 intro
01 intro01 intro
01 intro
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop 439-decorator
Stoop 439-decoratorStoop 439-decorator
Stoop 439-decorator
 
14 - Exceptions
14 - Exceptions14 - Exceptions
14 - Exceptions
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 

Ähnlich wie 5 - OOP - Smalltalk in a Nutshell (c)

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
 
mooc_presentataion_mayankmanral on the subject puthon
mooc_presentataion_mayankmanral on the subject puthonmooc_presentataion_mayankmanral on the subject puthon
mooc_presentataion_mayankmanral on the subject puthongarvitbisht27
 
Guaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in RustGuaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in Rustnikomatsakis
 
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
 
Standard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingStandard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingMandeep Singh
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...Francesco Casalegno
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowLightbend
 
Rust "Hot or Not" at Sioux
Rust "Hot or Not" at SiouxRust "Hot or Not" at Sioux
Rust "Hot or Not" at Siouxnikomatsakis
 
Ruby basics ||
Ruby basics ||Ruby basics ||
Ruby basics ||datt30
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures CodingMax Kleiner
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming LanguageNicolò Calcavecchia
 
Lecture 3: Storage and Variables
Lecture 3: Storage and VariablesLecture 3: Storage and Variables
Lecture 3: Storage and VariablesEelco Visser
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 

Ähnlich wie 5 - OOP - Smalltalk in a Nutshell (c) (20)

8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)
 
9 - OOP - Smalltalk Classes (a)
9 - OOP - Smalltalk Classes (a)9 - OOP - Smalltalk Classes (a)
9 - OOP - Smalltalk Classes (a)
 
mooc_presentataion_mayankmanral on the subject puthon
mooc_presentataion_mayankmanral on the subject puthonmooc_presentataion_mayankmanral on the subject puthon
mooc_presentataion_mayankmanral on the subject puthon
 
Guaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in RustGuaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in Rust
 
4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)4 - OOP - Taste of Smalltalk (Tamagoshi)
4 - OOP - Taste of Smalltalk (Tamagoshi)
 
Standard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingStandard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented Programming
 
Scala Paradigms
Scala ParadigmsScala Paradigms
Scala Paradigms
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To Know
 
Rust "Hot or Not" at Sioux
Rust "Hot or Not" at SiouxRust "Hot or Not" at Sioux
Rust "Hot or Not" at Sioux
 
Ruby basics ||
Ruby basics ||Ruby basics ||
Ruby basics ||
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntax
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures Coding
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
Lecture 3: Storage and Variables
Lecture 3: Storage and VariablesLecture 3: Storage and Variables
Lecture 3: Storage and Variables
 
Why Haskell
Why HaskellWhy Haskell
Why Haskell
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 

Mehr von The World of Smalltalk (19)

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
 
10 reflection
10 reflection10 reflection
10 reflection
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
04 idioms
04 idioms04 idioms
04 idioms
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
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 ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 

Kürzlich hochgeladen

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Kürzlich hochgeladen (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

5 - OOP - Smalltalk in a Nutshell (c)

  • 1. Stéphane Ducasse 1 Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ Smalltalk in a Nutshell
  • 2. S.Ducasse 2 Goals Syntax in a Nutshell OO Model in a Nutshell
  • 3. S.Ducasse 3 Smalltalk OO Model ***Everything*** is an object Only message passing Only late binding Instance variables are private to the object Methods are public Everything is a pointer Garbage collector Single inheritance between classes Only message passing between objects
  • 4. S.Ducasse 4 Complete Syntax on a PostCard exampleWithNumber: x “A method that illustrates every part of Smalltalk method syntax except primitives. It has unary, binary, and key word messages, declares arguments and temporaries (but not block temporaries), accesses a global variable (but not and instance variable), uses literals (array, character, symbol, string, integer, float), uses the pseudo variable true false, nil, self, and super, and has sequence, assignment, return and cascade. It has both zero argument and one argument blocks. It doesn’t do anything useful, though” |y| true & false not & (nil isNil) ifFalse: [self halt]. y := self size + super size. #($a #a ‘a’ 1 1.0) do: [:each | Transcript show: (each class name); show: (each printString); show:‘ ‘]. ^ x < y
  • 5. S.Ducasse 5 Language Constructs ^ return “ comments # symbol or array ‘ string [ ] block or byte array . separator and not terminator (or namespace access inVW) ; cascade (sending several messages to the same instance) | local or block variable := assignment $ character : end of selector name e, r number exponent or radix ! file element separator <primitive: ...> forVM primitive calls
  • 6. S.Ducasse 6 Syntax comment: “a comment” character: $c $h $a $r $a $c $t $e $r $s $# $@ string: ‘a nice string’ ‘lulu’ ‘l’’idiot’ symbol: #mac #+ array: #(1 2 3 (1 3) $a 4) byte array: #[1 2 3] integer: 1, 2r101 real: 1.5, 6.03e-34,4, 2.4e7 float: 1/33 boolean: true, false point: 10@120 Note that @ is not an element of the syntax, but just a message sent to a number.This is the same for /, bitShift, ifTrue:, do: ...
  • 7. S.Ducasse 7 Syntax in a Nutshell (II) assigment: var := aValue block: [:var ||tmp| expr...] temporary variable: |tmp| block variable: :var unary message: receiver selector binary message: receiver selector argument keyword based: receiver keyword1: arg1 keyword2: arg2... cascade: message ; selector ... separator: message . message result: ^ parenthesis: (...)
  • 8. S.Ducasse 8 NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1' classVariableNames: 'classVarName1' poolDictionaries: '' category: 'LAN' Class Definition in St-80
  • 9. S.Ducasse 9 Method Definition • Normally defined in a browser or (by directly invoking the compiler) • Methods are public • Always return self Node>>accept: thePacket "If the packet is addressed to me, print it. Else just behave like a normal node" (thePacket isAddressedTo: self) ifTrue: [self print: thePacket] ifFalse: [super accept: thePacket]
  • 10. S.Ducasse 10 • ‘1’,‘abc’ • Basic class creation messages are new, new:, basicNew, basicNew: Monster new • Class specific message creation (messages sent to classes) Tomagoshi withHunger: 10
  • 11. S.Ducasse 11 Messages and their Composition Three kinds of messages Unary: Node new Binary: 1 + 2, 3@4 Keywords: aTomagoshi eat: #cooky furiously: true Message Priority (Msg) > unary > binary > keywords Same Level from left to right Example: (10@0 extent: 10@100) bottomRight s isNil ifTrue: [ self halt ]
  • 12. S.Ducasse 12 • Anonymous method • Passed as method argument or stored • Functions fct(x)= x*x+3, fct(2). fct :=[:x| x * x + 3]. fct value: 2 Integer>>factorial | tmp | tmp:= 1. 2 to: self do: [:i| tmp := tmp * i] #(1 2 3) do: [:each | Transcript show: each printString ; cr] Blocks
  • 13. S.Ducasse 13 Yes ifTrue: is sent to a boolean Weather isRaining ifTrue: [self takeMyUmbrella] ifFalse: [self takeMySunglasses] ifTrue:ifFalse is sent to an object: a boolean!
  • 14. S.Ducasse 14 Yes a collection is iterating on itself #(1 2 -4 -86) do: [:each | Transcript show: each abs printString ;cr ] > 1 > 2 > 4 > 86 Yes we ask the collection object to perform the loop on itself
  • 15. S.Ducasse 15 Summary Objects and Messages Three kinds of messages unary binary keywords Block: a.k.a innerclass or closures or lambda Unary>Binary>Keywords
  • 16. S.Ducasse 16 Goals Syntax in a Nutshell OO Model in a Nutshell
  • 17. S.Ducasse 17 Instance and Class • Only one model • Uniformly applied • Classes are objects too
  • 18. S.Ducasse 18 Lookup…Class + Inheritance 1 2
  • 19. S.Ducasse 19 Classes are objects too • Instance creation is just a message send to a ... Class • Same method lookup than with any other objects • a Class is the single instance of amanonymous class • Point is the single instance of Point class
  • 21. S.Ducasse 21 Lookup and Class Methods 1 2 1 2 Workstation withName: ‘BigMac’ aWorkstation name
  • 23. S.Ducasse 23 Summary - Everything is an object - One single model - Single inheritance - Public methods - Protected attributes - Classes are simply objects too - Class is instance of another class - One unique method lookup look in the class of the receiver