S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Duca...
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 refere...
S.Ducasse 4
A LAN Simulator
A LAN contains nodes, workstations, printers, file servers.
Packets are sent in a LAN and each...
S.Ducasse 5
Three Kinds of Objects
Node and its subclasses represent the entities that are
connected to form a LAN.
Packet...
S.Ducasse 6
LAN Design
Node
WorkstationPrinter
NetworkManager
Packet
addressee
contents
originator
isSentBy: aNode
isAddre...
S.Ducasse 7
Interactions Between Nodes
accept: aPacket
send: aPacket
nodePrinter aPacket node1
isAddressedTo: nodePrinter
...
S.Ducasse 8
Node and Packet Creation
|macNode pcNode node1 printerNode node2 node3 packet|
macNode := Workstation withName...
S.Ducasse 9
Objects sends Messages
• Message: 1 + 2
– receiver : 1 (an instance of SmallInteger)
– selector: #+
– argument...
S.Ducasse 10
Transmitting a Packet
| aLan packet macNode|
...
macNode := aLan findNodeWithAddress: #mac.
packet := Packet ...
S.Ducasse 11
How to Define a Class (Sq)
• Fill the template:
NameOfSuperclass subclass: #NameOfClass
instanceVariableNames...
S.Ducasse 12
Smalltalk defineClass: #Packet
superclass: #{Object}
indexedType: #none
private: false
instanceVariableNames:...
S.Ducasse 13
How to define a method?
message selector and argument names
"comment stating purpose of message"
| temporary ...
S.Ducasse 14
In Java
In Java we would write
void accept(thePacket Packet)
/*If the packet is addressed to me, print it. Ot...
S.Ducasse 15
Summary
Define a class
Define a method
Upcoming SlideShare
Loading in …5
×

6 - OOP - LAN Example

1,237 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,237
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

6 - OOP - LAN Example

  1. 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. 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  3. 3. S.Ducasse 3 Outline • Simulate a LAN physically • Set up a context for • future chapters • Exercises • Some forward references to intriguate you
  4. 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. 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. 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. 7. S.Ducasse 7 Interactions Between Nodes accept: aPacket send: aPacket nodePrinter aPacket node1 isAddressedTo: nodePrinter accept: aPacket print: aPacket [true] [false]
  8. 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. 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. 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. 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. 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. 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. 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. 15. S.Ducasse 15 Summary Define a class Define a method

×