SlideShare une entreprise Scribd logo
1  sur  15
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/
Let’s Play Objects
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
Outline
• Simulate a LAN physically
• Set up a context for
• future chapters
• Exercises
• Some forward references to intriguate you
S.Ducasse 4
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 5
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 6
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 7
Interactions Between Nodes
accept: aPacket
send: aPacket
nodePrinter aPacket node1
isAddressedTo: nodePrinter
accept: aPacket
print: aPacket
[true]
[false]
S.Ducasse 8
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 9
Objects sends 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 ofWorkstation)
• 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 10
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 11
How to Define a Class (Sq)
• Fill the template:
NameOfSuperclass subclass: #NameOfClass
instanceVariableNames: 'instVarName1'
classVariableNames: 'ClassVarName1 ClassVarName2'
poolDictionaries: ''
category: 'LAN’
• For example to create the class Packet
Object subclass: #Packet
instanceVariableNames: 'addressee originator contents '
classVariableNames: ''
poolDictionaries: ''
category: 'LAN'
S.Ducasse 12
Smalltalk defineClass: #Packet
superclass: #{Object}
indexedType: #none
private: false
instanceVariableNames: 'addressee originator contents'
classInstanceVariableNames: ''
imports: ''
category: 'LAN'
How to Define a Class (VW)
S.Ducasse 13
How to define a method?
message selector and argument names
"comment stating purpose of message"
| temporary variable names |
statements
LanPrinter>>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 14
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 15
Summary
Define a class
Define a method

Contenu connexe

Tendances

General commands for navisphere cli
General commands for navisphere cliGeneral commands for navisphere cli
General commands for navisphere cli
msaleh1234
 

Tendances (20)

GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Docker meetup
Docker meetupDocker meetup
Docker meetup
 
Swarm mode
Swarm modeSwarm mode
Swarm mode
 
Inteligencia artificial 13
Inteligencia artificial 13Inteligencia artificial 13
Inteligencia artificial 13
 
macvlan and ipvlan
macvlan and ipvlanmacvlan and ipvlan
macvlan and ipvlan
 
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
 
Linux cgroups and namespaces
Linux cgroups and namespacesLinux cgroups and namespaces
Linux cgroups and namespaces
 
Namespace
NamespaceNamespace
Namespace
 
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...
 
Docker Network Overview and legacy "--link"
Docker Network Overview and legacy "--link"Docker Network Overview and legacy "--link"
Docker Network Overview and legacy "--link"
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
General commands for navisphere cli
General commands for navisphere cliGeneral commands for navisphere cli
General commands for navisphere cli
 
Docker Networking & Swarm Mode Introduction
Docker Networking & Swarm Mode IntroductionDocker Networking & Swarm Mode Introduction
Docker Networking & Swarm Mode Introduction
 
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
 
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
 
Namespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containersNamespaces and cgroups - the basis of Linux containers
Namespaces and cgroups - the basis of Linux containers
 
Conda environment system & how to use it on CSUC machines
Conda environment system & how to use it on CSUC machinesConda environment system & how to use it on CSUC machines
Conda environment system & how to use it on CSUC machines
 
Sticky bit suid sgid
Sticky bit suid sgidSticky bit suid sgid
Sticky bit suid sgid
 
Linux administration training
Linux administration trainingLinux administration training
Linux administration training
 

Similaire à 6 - OOP - LAN Example

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
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
Wajath
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
Jayaprasanna4
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
James Dennis
 

Similaire à 6 - OOP - LAN Example (20)

4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)4 - OOP - Taste of Smalltalk (Squeak)
4 - OOP - Taste of Smalltalk (Squeak)
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
 
Ns2pre
Ns2preNs2pre
Ns2pre
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
 
Introduction to NS2 - Cont..
Introduction to NS2 - Cont..Introduction to NS2 - Cont..
Introduction to NS2 - Cont..
 
VLANs in the Linux Kernel
VLANs in the Linux KernelVLANs in the Linux Kernel
VLANs in the Linux Kernel
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
Ns2
Ns2Ns2
Ns2
 
DEF CON 27 - workshop - HUGO TROVAO and RUSHIKESH NADEDKAR - scapy dojo v1
DEF CON 27 - workshop - HUGO TROVAO and RUSHIKESH NADEDKAR - scapy dojo v1DEF CON 27 - workshop - HUGO TROVAO and RUSHIKESH NADEDKAR - scapy dojo v1
DEF CON 27 - workshop - HUGO TROVAO and RUSHIKESH NADEDKAR - scapy dojo v1
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on Lab
 

Plus de 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
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
02 basics
02 basics02 basics
02 basics
 
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 sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 

Dernier

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

6 - OOP - LAN Example

  • 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/ Let’s Play Objects
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 Outline • Simulate a LAN physically • Set up a context for • future chapters • Exercises • Some forward references to intriguate you
  • 4. S.Ducasse 4 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
  • 5. S.Ducasse 5 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
  • 6. S.Ducasse 6 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
  • 7. S.Ducasse 7 Interactions Between Nodes accept: aPacket send: aPacket nodePrinter aPacket node1 isAddressedTo: nodePrinter accept: aPacket print: aPacket [true] [false]
  • 8. S.Ducasse 8 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.
  • 9. S.Ducasse 9 Objects sends 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 ofWorkstation) • Message: Packet send: 'This packet travelled to' to: #lpr – receiver: Packet (a class) – selector: #send:to: – arguments: 'This packet travelled to' and #lpr
  • 10. S.Ducasse 10 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
  • 11. S.Ducasse 11 How to Define a Class (Sq) • Fill the template: NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1' classVariableNames: 'ClassVarName1 ClassVarName2' poolDictionaries: '' category: 'LAN’ • For example to create the class Packet Object subclass: #Packet instanceVariableNames: 'addressee originator contents ' classVariableNames: '' poolDictionaries: '' category: 'LAN'
  • 12. S.Ducasse 12 Smalltalk defineClass: #Packet superclass: #{Object} indexedType: #none private: false instanceVariableNames: 'addressee originator contents' classInstanceVariableNames: '' imports: '' category: 'LAN' How to Define a Class (VW)
  • 13. S.Ducasse 13 How to define a method? message selector and argument names "comment stating purpose of message" | temporary variable names | statements LanPrinter>>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]
  • 14. S.Ducasse 14 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)}
  • 15. S.Ducasse 15 Summary Define a class Define a method