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

More Related Content

PDF
Namespaces in Linux
PPTX
Introduction to-linux
PDF
GopherFest 2017 - Adding Context to NATS
PDF
Docker swarm workshop
PDF
Pipework: Software-Defined Network for Containers and Docker
PDF
Linux class 9 15 oct 2021-5
PDF
Linux class 10 15 oct 2021-6
PPT
Bootcamp linux commands
Namespaces in Linux
Introduction to-linux
GopherFest 2017 - Adding Context to NATS
Docker swarm workshop
Pipework: Software-Defined Network for Containers and Docker
Linux class 9 15 oct 2021-5
Linux class 10 15 oct 2021-6
Bootcamp linux commands

What's hot (20)

PDF
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
PDF
Introduction to ns2
PPTX
Docker meetup
PDF
Swarm mode
PDF
Inteligencia artificial 13
PDF
macvlan and ipvlan
PDF
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
PDF
Linux cgroups and namespaces
PPT
Namespace
PDF
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
ODP
Docker Network Overview and legacy "--link"
PPT
Linux Commands
DOCX
General commands for navisphere cli
PPTX
Docker Networking & Swarm Mode Introduction
PDF
Containers and Namespaces in the Linux Kernel
PDF
Introduction to Docker and deployment and Azure
PDF
Namespaces and cgroups - the basis of Linux containers
PDF
Conda environment system & how to use it on CSUC machines
PDF
Sticky bit suid sgid
PPTX
Linux administration training
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
Introduction to ns2
Docker meetup
Swarm mode
Inteligencia artificial 13
macvlan and ipvlan
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
Linux cgroups and namespaces
Namespace
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Docker Network Overview and legacy "--link"
Linux Commands
General commands for navisphere cli
Docker Networking & Swarm Mode Introduction
Containers and Namespaces in the Linux Kernel
Introduction to Docker and deployment and Azure
Namespaces and cgroups - the basis of Linux containers
Conda environment system & how to use it on CSUC machines
Sticky bit suid sgid
Linux administration training
Ad

Similar to 6 - OOP - LAN Example (20)

PPT
4 - OOP - Taste of Smalltalk (VisualWorks)
PPT
4 - OOP - Taste of Smalltalk (Squeak)
PPT
Network Simulator Tutorial
PDF
18CSL51 - Network Lab Manual.pdf
DOCX
NS2 (1).docx
PDF
Ns2pre
PPT
NS2-tutorial.ppt
PDF
Cs757 ns2-tutorial-exercise
PDF
study-of-network-simulator.pdf
PDF
NS2-tutorial.pdf
PPT
Ns network simulator
PPT
Venkat ns2
PPTX
Working with NS2
PPT
Introduction to NS2 - Cont..
PPTX
NErwork Lab Simulation Introduction.pptx
PDF
VLANs in the Linux Kernel
PPTX
ZeroMQ: Super Sockets - by J2 Labs
PPT
Tut hemant ns2
PDF
DEF CON 27 - workshop - HUGO TROVAO and RUSHIKESH NADEDKAR - scapy dojo v1
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (Squeak)
Network Simulator Tutorial
18CSL51 - Network Lab Manual.pdf
NS2 (1).docx
Ns2pre
NS2-tutorial.ppt
Cs757 ns2-tutorial-exercise
study-of-network-simulator.pdf
NS2-tutorial.pdf
Ns network simulator
Venkat ns2
Working with NS2
Introduction to NS2 - Cont..
NErwork Lab Simulation Introduction.pptx
VLANs in the Linux Kernel
ZeroMQ: Super Sockets - by J2 Labs
Tut hemant ns2
DEF CON 27 - workshop - HUGO TROVAO and RUSHIKESH NADEDKAR - scapy dojo v1
Ad

More from The World of Smalltalk (20)

PDF
05 seaside canvas
PPT
PPT
12 virtualmachine
PPT
PPT
10 reflection
PPT
09 metaclasses
PPT
08 refactoring
PPT
07 bestpractice
PPT
PPT
PPT
03 standardclasses
PPT
Stoop sed-smells
PPT
Stoop sed-sharing ornot
PPT
Stoop sed-class initialization
PPT
Stoop sed-class initialization
PPT
Stoop metaclasses
05 seaside canvas
12 virtualmachine
10 reflection
09 metaclasses
08 refactoring
07 bestpractice
03 standardclasses
Stoop sed-smells
Stoop sed-sharing ornot
Stoop sed-class initialization
Stoop sed-class initialization
Stoop metaclasses

Recently uploaded (20)

PDF
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Race Reva University – Shaping Future Leaders in Artificial Intelligence
PPTX
Module on health assessment of CHN. pptx
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
HVAC Specification 2024 according to central public works department
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Empowerment Technology for Senior High School Guide
PDF
semiconductor packaging in vlsi design fab
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PDF
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic
LIFE & LIVING TRILOGY - PART - (2) THE PURPOSE OF LIFE.pdf
Computer Architecture Input Output Memory.pptx
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Race Reva University – Shaping Future Leaders in Artificial Intelligence
Module on health assessment of CHN. pptx
Core Concepts of Personalized Learning and Virtual Learning Environments
Share_Module_2_Power_conflict_and_negotiation.pptx
HVAC Specification 2024 according to central public works department
B.Sc. DS Unit 2 Software Engineering.pptx
Cambridge-Practice-Tests-for-IELTS-12.docx
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
Empowerment Technology for Senior High School Guide
semiconductor packaging in vlsi design fab
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Hazard Identification & Risk Assessment .pdf
LEARNERS WITH ADDITIONAL NEEDS ProfEd Topic

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