SlideShare a Scribd company logo
1 of 30
Download to read offline
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
The Taste of Smalltalk
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
Goals
•Two examples:
•“hello world”
•a LAN simulator
•To give you an idea of:
•the syntax
•the elementary objects and classes
•the environment
•To provide the basis for all the lectures:
•all the code examples,
•constructs,
•design decisions, ...
S.Ducasse 4
An Advice
You do not have to know everything!!!
•“Try not to care - Beginning Smalltalk programmers often
have trouble because they think they need to understand all
the details of how a thing works before they can use it.This
means it takes quite a while before they can master Transcript
show:‘Hello World’. One of the great leaps in OO is to be
able to answer the question "How does this work?" with "I
don’t care"“.Alan Knight. Smalltalk Guru
• We will show you how to learn and find your way
S.Ducasse 5
Some Conventions
• ReturnValues
• 1 + 3 -> 4
• Node new -> aNode
• Method selector #add:
• Method scope conventions
• Instance Method defined in class Node:
• Node>>accept: aPacket
• Class Method defined in class Node (in the class of
the the class Node)
• Node class>>withName: aSymbol
• aSomething is an instance of the class Something
S.Ducasse 6
Roadmap
•“hello world”
• Syntax
• a LAN simulator
S.Ducasse 7
Hello World
Transcript show:‘hello world’
•At anytime we can dynamically ask the system to evaluate an
expression.To evaluate an expression, select it and with the
middle mouse button apply doIt.
•Transcript is a special object that is a kind of standard
output.
•It refers to a TextCollector instance associated with the
launcher.
S.Ducasse 8
Transcript show:‘hello world’
S.Ducasse 9
Everything is an Object
The workspace is an object.
The window is an object: it is an instance of ApplicationWindow.
The text editor is an object: it is an instance of ParagraphEditor.
The scrollbars are objects too.
‘hello word’ is an object: it is aString instance of String.
#show: is a Symbol that is also an object.
The mouse is an object.
The parser is an object: instance of Parser.
The compiler is also an object: instance of Compiler.
The process scheduler is also an object.
The garbage collector is an object: instance of MemoryObject.
Smalltalk is a consistent, uniform world written in itself.You can learn how
it is implemented, you can extend it or even modify it.All the code is
available and readable
S.Ducasse 10
Smalltalk Object 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 11
Roadmap
• Hello World
• First look at the syntax
• LAN Simulator
S.Ducasse 12
Complete Syntax on a PostCard
exampleWithNumber: x
“Illustrates every part of Smalltalk method syntax. It has unary, binary, and key
word messages, declares arguments and 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.”
|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 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
DoIt, PrintIt, InspectIt and Accept
• Accept = Compile: Accept a method or a class
definition
• DoIt: send a message to an object
• PrintIt: send a message to an object + print the result
(#printOn:)
• InspectIt: send a message to an object + inspect the
result (#inspect)
S.Ducasse 16
Objects send messages
• Transcript show:‘hello world’
• The above expression is a message
• the object Transcript is the receiver of the message
• the selector of the message is #show:
• one argument: a string ‘hello world’
• Transcript is a global variable (starts with an uppercase
letter) that refers to the Launcher’s report part.
S.Ducasse 17
Vocabulary Point
Message passing or sending a message is equivalent to
invoking a method in Java or C++
calling a procedure in procedural languages
applying a function in functional languages
of course the last two points must be considered under
the light of polymorphism
S.Ducasse 18
Roadmap
• Hello World
• First look at the syntax
• LAN Simulator
S.Ducasse 19
A LAN Simulator
A LAN contains nodes, workstations, printers, file
servers. Packets are sent in a LAN and each node treats
them differently.
mac
node3
node2
pcnode1
lpr
S.Ducasse 20
Three Kinds of Objects
Node and its subclasses represent the entities that are
connected to form a LAN.
Packet represents the information that flows between
Nodes.
NetworkManager manages how the nodes are
connected
S.Ducasse 21
LAN Design
Node
WorkstationPrinter
NetworkManager
Packet
addressee
contents
originator
isSentBy: aNode
isAddressedTo: aNode
name
accept: aPacket
send: aPacket
hasNextNode
originate: aPacket
accept: aPacket
print: aPacket
accept: aPacket
declareNode: aNode
undeclareNode: aNode
connectNodes: anArrayOfAddressees nextNode
S.Ducasse 22
Interactions Between Nodes
accept: aPacket
send: aPacket
nodePrinter aPacket node1
isAddressedTo: nodePrinter
accept: aPacket
print: aPacket
[true]
[false]
S.Ducasse 23
Node and Packet Creation
|macNode pcNode node1 printerNode node2 node3 packet|
macNode := Workstation withName: #mac.
pcNode := Workstation withName: #pc.
node1 := Node withName: #node1.
node2 := Node withName: #node2.
node3 := Node withName: #node2.
printerNode := Printer withName: #lpr.
macNode nextNode: node1.
node1 nextNode: pcNode.
pcNode nextNode: node2.
node3 nextNode: printerNode.
lpr nextNode: macNode.
packet := Packet send: 'This packet travelled to' to: #lpr.
S.Ducasse 24
Objects Send Messages
Message: 1 + 2
receiver : 1 (an instance of SmallInteger)
selector: #+
arguments: 2
Message: lpr nextNode: macNode
receiver: lpr (an instance of LanPrinter)
selector: #nextNode:
arguments: macNode (an instance of Workstation)
Message: Packet send: 'This packet travelled to' to: #lpr
receiver: Packet (a class)
selector: #send:to:
arguments: 'This packet travelled to' and #lpr
S.Ducasse 25
Transmitting a Packet
| aLan packet macNode|
...
macNode := aLan findNodeWithAddress: #mac.
packet := Packet send: 'This packet travelled to the printer' to:
#lpr.
macNode originate: packet.
-> mac sends a packet to pc
-> pc sends a packet to node1
-> node1 sends a packet to node2
-> node2 sends a packet to node3
-> node3 sends a packet to lpr
-> lpr is printing
-> this packet travelled to lpr
S.Ducasse 26
Smalltalk defineClass: #Packet
superclass: #{Object}
indexedType: #none
private: false
instanceVariableNames: 'addressee
originator contents'
classInstanceVariableNames: ''
imports: ''
category: 'LAN'
How to Define a Class?
S.Ducasse 27
NameOfSuperclass subclass: #NameOfClass
instanceVariableNames: 'instVarName1'
classVariableNames: 'classVarName1'
poolDictionaries: ''
category: 'LAN'
How to Define a Class?
S.Ducasse 28
How to Define a Method?
message selector and argument names
"comment stating purpose of message"
| temporary variable names |
statements
accept: thePacket
"If the packet is addressed to me, print it. Otherwise just
behave like a normal node."
(thePacket isAddressedTo: self)
ifTrue: [self print: thePacket]
ifFalse: [super accept: thePacket]
S.Ducasse 29
In Java
• In Java we would write
void accept(thePacket Packet)
/*If the packet is addressed to me, print it. Otherwise just
behave like a normal node.*/
if (thePacket.isAddressedTo(this)){
this.print(thePacket)}
else super.accept(thePacket)}
S.Ducasse 30
Summary
What is a message?
What is the message receiver?
What is the method selector?
How to create a class?
How to define a method?

More Related Content

What's hot

Introduction to Docker and deployment and Azure
Introduction to Docker and deployment and AzureIntroduction to Docker and deployment and Azure
Introduction to Docker and deployment and AzureJérôme Petazzoni
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConJérôme Petazzoni
 
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...Jérôme Petazzoni
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Jérôme Petazzoni
 
OCaml Labs introduction at OCaml Consortium 2012
OCaml Labs introduction at OCaml Consortium 2012OCaml Labs introduction at OCaml Consortium 2012
OCaml Labs introduction at OCaml Consortium 2012Anil Madhavapeddy
 
Node.js at Joyent: Engineering for Production
Node.js at Joyent: Engineering for ProductionNode.js at Joyent: Engineering for Production
Node.js at Joyent: Engineering for Productionjclulow
 
LXC, Docker, security: is it safe to run applications in Linux Containers?
LXC, Docker, security: is it safe to run applications in Linux Containers?LXC, Docker, security: is it safe to run applications in Linux Containers?
LXC, Docker, security: is it safe to run applications in Linux Containers?Jérôme Petazzoni
 
Cloudstack collaboration conference Europe - SDN and Devops
Cloudstack collaboration conference Europe - SDN and DevopsCloudstack collaboration conference Europe - SDN and Devops
Cloudstack collaboration conference Europe - SDN and DevopsJohn Willis
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Neeraj Shrimali
 
Seven problems of Linux Containers
Seven problems of Linux ContainersSeven problems of Linux Containers
Seven problems of Linux ContainersKirill Kolyshkin
 
Containers and Namespaces in the Linux Kernel
Containers and Namespaces in the Linux KernelContainers and Namespaces in the Linux Kernel
Containers and Namespaces in the Linux KernelOpenVZ
 
Introducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpaddenIntroducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpaddenmacbrained
 
Containerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationContainerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationC4Media
 
Union FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerUnion FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerKnoldus Inc.
 
Docker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme PetazzoniDocker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme PetazzoniDocker, Inc.
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containersGoogle
 
Linux cgroups and namespaces
Linux cgroups and namespacesLinux cgroups and namespaces
Linux cgroups and namespacesLocaweb
 

What's hot (20)

Introduction to Docker and deployment and Azure
Introduction to Docker and deployment and AzureIntroduction to Docker and deployment and Azure
Introduction to Docker and deployment and Azure
 
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxConAnatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
 
OCaml Labs introduction at OCaml Consortium 2012
OCaml Labs introduction at OCaml Consortium 2012OCaml Labs introduction at OCaml Consortium 2012
OCaml Labs introduction at OCaml Consortium 2012
 
Node.js at Joyent: Engineering for Production
Node.js at Joyent: Engineering for ProductionNode.js at Joyent: Engineering for Production
Node.js at Joyent: Engineering for Production
 
LXC, Docker, security: is it safe to run applications in Linux Containers?
LXC, Docker, security: is it safe to run applications in Linux Containers?LXC, Docker, security: is it safe to run applications in Linux Containers?
LXC, Docker, security: is it safe to run applications in Linux Containers?
 
Cloudstack collaboration conference Europe - SDN and Devops
Cloudstack collaboration conference Europe - SDN and DevopsCloudstack collaboration conference Europe - SDN and Devops
Cloudstack collaboration conference Europe - SDN and Devops
 
Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup. Linux container, namespaces & CGroup.
Linux container, namespaces & CGroup.
 
Seven problems of Linux Containers
Seven problems of Linux ContainersSeven problems of Linux Containers
Seven problems of Linux Containers
 
Containers and Namespaces in the Linux Kernel
Containers and Namespaces in the Linux KernelContainers and Namespaces in the Linux Kernel
Containers and Namespaces in the Linux Kernel
 
Introducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpaddenIntroducing Docker to Mac Management – Nick McSpadden
Introducing Docker to Mac Management – Nick McSpadden
 
Containerization Is More than the New Virtualization
Containerization Is More than the New VirtualizationContainerization Is More than the New Virtualization
Containerization Is More than the New Virtualization
 
Union FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerUnion FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a Container
 
Docker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme PetazzoniDocker storage drivers by Jérôme Petazzoni
Docker storage drivers by Jérôme Petazzoni
 
Introduction to linux containers
Introduction to linux containersIntroduction to linux containers
Introduction to linux containers
 
Linux cgroups and namespaces
Linux cgroups and namespacesLinux cgroups and namespaces
Linux cgroups and namespaces
 
Lxc- Introduction
Lxc- IntroductionLxc- Introduction
Lxc- Introduction
 

Similar to 4 - OOP - Taste of Smalltalk (VisualWorks)

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
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets CocoaRobbert
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26Max Kleiner
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsJames Dennis
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures CodingMax Kleiner
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxkishore1986
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linuxrowiebornia
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptxDavidMaina47
 
Docker Security
Docker SecurityDocker Security
Docker SecurityBladE0341
 

Similar to 4 - OOP - Taste of Smalltalk (VisualWorks) (20)

4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)
 
6 - OOP - LAN Example
6 - OOP - LAN Example6 - OOP - LAN Example
6 - OOP - LAN Example
 
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
 
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)
 
8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
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)
 
02 basics
02 basics02 basics
02 basics
 
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)
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets Cocoa
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures Coding
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 
Docker Security
Docker SecurityDocker Security
Docker Security
 

More from The World of Smalltalk (20)

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
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
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 metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 

Recently uploaded

THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...Subham Panja
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptxmary850239
 
Material Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.pptMaterial Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.pptBanaras Hindu University
 
Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchRushdi Shams
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...Sandy Millin
 
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxBBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxProf. Kanchan Kumari
 
ICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdfICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdfVanessa Camilleri
 
Quantitative research methodology and survey design
Quantitative research methodology and survey designQuantitative research methodology and survey design
Quantitative research methodology and survey designBalelaBoru
 
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandThe OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandDr. Sarita Anand
 
Awards Presentation 2024 - March 12 2024
Awards Presentation 2024 - March 12 2024Awards Presentation 2024 - March 12 2024
Awards Presentation 2024 - March 12 2024bsellato
 
VIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfVIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfArthyR3
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsDhatriParmar
 
3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptxmary850239
 
The First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfThe First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfdogden2
 
UNIT I Design Thinking and Explore.pptx
UNIT I  Design Thinking and Explore.pptxUNIT I  Design Thinking and Explore.pptx
UNIT I Design Thinking and Explore.pptxGOWSIKRAJA PALANISAMY
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxheathfieldcps1
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxiammrhaywood
 
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSDLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSTeacherNicaPrintable
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptxmary850239
 

Recently uploaded (20)

THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx
 
Material Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.pptMaterial Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.ppt
 
Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...
 
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxBBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
 
ICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdfICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdf
 
Quantitative research methodology and survey design
Quantitative research methodology and survey designQuantitative research methodology and survey design
Quantitative research methodology and survey design
 
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandThe OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
 
Awards Presentation 2024 - March 12 2024
Awards Presentation 2024 - March 12 2024Awards Presentation 2024 - March 12 2024
Awards Presentation 2024 - March 12 2024
 
VIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdfVIT336 – Recommender System - Unit 3.pdf
VIT336 – Recommender System - Unit 3.pdf
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian Poetics
 
3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx
 
The First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfThe First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdf
 
UNIT I Design Thinking and Explore.pptx
UNIT I  Design Thinking and Explore.pptxUNIT I  Design Thinking and Explore.pptx
UNIT I Design Thinking and Explore.pptx
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
 
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSDLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx
 

4 - OOP - Taste of Smalltalk (VisualWorks)

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse Stephane.Ducasse@univ-savoie.fr http://www.listic.univ-savoie.fr/~ducasse/ The Taste of Smalltalk
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 Goals •Two examples: •“hello world” •a LAN simulator •To give you an idea of: •the syntax •the elementary objects and classes •the environment •To provide the basis for all the lectures: •all the code examples, •constructs, •design decisions, ...
  • 4. S.Ducasse 4 An Advice You do not have to know everything!!! •“Try not to care - Beginning Smalltalk programmers often have trouble because they think they need to understand all the details of how a thing works before they can use it.This means it takes quite a while before they can master Transcript show:‘Hello World’. One of the great leaps in OO is to be able to answer the question "How does this work?" with "I don’t care"“.Alan Knight. Smalltalk Guru • We will show you how to learn and find your way
  • 5. S.Ducasse 5 Some Conventions • ReturnValues • 1 + 3 -> 4 • Node new -> aNode • Method selector #add: • Method scope conventions • Instance Method defined in class Node: • Node>>accept: aPacket • Class Method defined in class Node (in the class of the the class Node) • Node class>>withName: aSymbol • aSomething is an instance of the class Something
  • 6. S.Ducasse 6 Roadmap •“hello world” • Syntax • a LAN simulator
  • 7. S.Ducasse 7 Hello World Transcript show:‘hello world’ •At anytime we can dynamically ask the system to evaluate an expression.To evaluate an expression, select it and with the middle mouse button apply doIt. •Transcript is a special object that is a kind of standard output. •It refers to a TextCollector instance associated with the launcher.
  • 9. S.Ducasse 9 Everything is an Object The workspace is an object. The window is an object: it is an instance of ApplicationWindow. The text editor is an object: it is an instance of ParagraphEditor. The scrollbars are objects too. ‘hello word’ is an object: it is aString instance of String. #show: is a Symbol that is also an object. The mouse is an object. The parser is an object: instance of Parser. The compiler is also an object: instance of Compiler. The process scheduler is also an object. The garbage collector is an object: instance of MemoryObject. Smalltalk is a consistent, uniform world written in itself.You can learn how it is implemented, you can extend it or even modify it.All the code is available and readable
  • 10. S.Ducasse 10 Smalltalk Object 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
  • 11. S.Ducasse 11 Roadmap • Hello World • First look at the syntax • LAN Simulator
  • 12. S.Ducasse 12 Complete Syntax on a PostCard exampleWithNumber: x “Illustrates every part of Smalltalk method syntax. It has unary, binary, and key word messages, declares arguments and 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.” |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
  • 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 DoIt, PrintIt, InspectIt and Accept • Accept = Compile: Accept a method or a class definition • DoIt: send a message to an object • PrintIt: send a message to an object + print the result (#printOn:) • InspectIt: send a message to an object + inspect the result (#inspect)
  • 16. S.Ducasse 16 Objects send messages • Transcript show:‘hello world’ • The above expression is a message • the object Transcript is the receiver of the message • the selector of the message is #show: • one argument: a string ‘hello world’ • Transcript is a global variable (starts with an uppercase letter) that refers to the Launcher’s report part.
  • 17. S.Ducasse 17 Vocabulary Point Message passing or sending a message is equivalent to invoking a method in Java or C++ calling a procedure in procedural languages applying a function in functional languages of course the last two points must be considered under the light of polymorphism
  • 18. S.Ducasse 18 Roadmap • Hello World • First look at the syntax • LAN Simulator
  • 19. S.Ducasse 19 A LAN Simulator A LAN contains nodes, workstations, printers, file servers. Packets are sent in a LAN and each node treats them differently. mac node3 node2 pcnode1 lpr
  • 20. S.Ducasse 20 Three Kinds of Objects Node and its subclasses represent the entities that are connected to form a LAN. Packet represents the information that flows between Nodes. NetworkManager manages how the nodes are connected
  • 21. S.Ducasse 21 LAN Design Node WorkstationPrinter NetworkManager Packet addressee contents originator isSentBy: aNode isAddressedTo: aNode name accept: aPacket send: aPacket hasNextNode originate: aPacket accept: aPacket print: aPacket accept: aPacket declareNode: aNode undeclareNode: aNode connectNodes: anArrayOfAddressees nextNode
  • 22. S.Ducasse 22 Interactions Between Nodes accept: aPacket send: aPacket nodePrinter aPacket node1 isAddressedTo: nodePrinter accept: aPacket print: aPacket [true] [false]
  • 23. S.Ducasse 23 Node and Packet Creation |macNode pcNode node1 printerNode node2 node3 packet| macNode := Workstation withName: #mac. pcNode := Workstation withName: #pc. node1 := Node withName: #node1. node2 := Node withName: #node2. node3 := Node withName: #node2. printerNode := Printer withName: #lpr. macNode nextNode: node1. node1 nextNode: pcNode. pcNode nextNode: node2. node3 nextNode: printerNode. lpr nextNode: macNode. packet := Packet send: 'This packet travelled to' to: #lpr.
  • 24. S.Ducasse 24 Objects Send Messages Message: 1 + 2 receiver : 1 (an instance of SmallInteger) selector: #+ arguments: 2 Message: lpr nextNode: macNode receiver: lpr (an instance of LanPrinter) selector: #nextNode: arguments: macNode (an instance of Workstation) Message: Packet send: 'This packet travelled to' to: #lpr receiver: Packet (a class) selector: #send:to: arguments: 'This packet travelled to' and #lpr
  • 25. S.Ducasse 25 Transmitting a Packet | aLan packet macNode| ... macNode := aLan findNodeWithAddress: #mac. packet := Packet send: 'This packet travelled to the printer' to: #lpr. macNode originate: packet. -> mac sends a packet to pc -> pc sends a packet to node1 -> node1 sends a packet to node2 -> node2 sends a packet to node3 -> node3 sends a packet to lpr -> lpr is printing -> this packet travelled to lpr
  • 26. S.Ducasse 26 Smalltalk defineClass: #Packet superclass: #{Object} indexedType: #none private: false instanceVariableNames: 'addressee originator contents' classInstanceVariableNames: '' imports: '' category: 'LAN' How to Define a Class?
  • 27. S.Ducasse 27 NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1' classVariableNames: 'classVarName1' poolDictionaries: '' category: 'LAN' How to Define a Class?
  • 28. S.Ducasse 28 How to Define a Method? message selector and argument names "comment stating purpose of message" | temporary variable names | statements accept: thePacket "If the packet is addressed to me, print it. Otherwise just behave like a normal node." (thePacket isAddressedTo: self) ifTrue: [self print: thePacket] ifFalse: [super accept: thePacket]
  • 29. S.Ducasse 29 In Java • In Java we would write void accept(thePacket Packet) /*If the packet is addressed to me, print it. Otherwise just behave like a normal node.*/ if (thePacket.isAddressedTo(this)){ this.print(thePacket)} else super.accept(thePacket)}
  • 30. S.Ducasse 30 Summary What is a message? What is the message receiver? What is the method selector? How to create a class? How to define a method?