Скачать презентацию Let s Play Objects Stéphane Ducasse Stephane Ducasse univ-savoie fr Скачать презентацию Let s Play Objects Stéphane Ducasse Stephane Ducasse univ-savoie fr

e8988a86aaff3ed96f88ad4ea0c2d3b2.ppt

  • Количество слайдов: 15

Let’s Play Objects Stéphane Ducasse Stephane. Ducasse@univ-savoie. fr http: //www. listic. univ-savoie. fr/~ducasse/ S. Let’s Play Objects Stéphane Ducasse Stephane. [email protected] fr http: //www. listic. univ-savoie. fr/~ducasse/ S. Ducasse 1

License: CC-Attribution-Share. Alike 2. 0 http: //creativecommons. org/licenses/by-sa/2. 0/ S. Ducasse 2 License: CC-Attribution-Share. Alike 2. 0 http: //creativecommons. org/licenses/by-sa/2. 0/ S. Ducasse 2

Outline • • • S. Ducasse Simulate a LAN physically Set up a context Outline • • • S. Ducasse Simulate a LAN physically Set up a context for • • future chapters Exercises Some forward references to intriguate you 3

A LAN Simulator A LAN contains nodes, workstations, printers, file servers. Packets are sent A LAN Simulator A LAN contains nodes, workstations, printers, file servers. Packets are sent in a LAN and each node treats them differently. S. Ducasse 4

Three Kinds of Objects Node and its subclasses represent the entities that are connected 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. Network. Manager manages how the nodes are connected S. Ducasse 5

LAN Design S. Ducasse 6 LAN Design S. Ducasse 6

Interactions Between Nodes S. Ducasse 7 Interactions Between Nodes S. Ducasse 7

Node and Packet Creation |mac. Node pc. Node node 1 printer. Node node 2 Node and Packet Creation |mac. Node pc. Node node 1 printer. Node node 2 node 3 packet| mac. Node : = Workstation with. Name: #mac. pc. Node : = Workstation with. Name: #pc. node 1 : = Node with. Name: #node 1. node 2 : = Node with. Name: #node 2. node 3 : = Node with. Name: #node 2. printer. Node : = Printer with. Name: #lpr. mac. Node next. Node: node 1 next. Node: pc. Node next. Node: node 2. node 3 next. Node: printer. Node. lpr next. Node: mac. Node. packet : = Packet send: 'This packet travelled to' to: #lpr. S. Ducasse 8

Objects sends Messages • Message: 1 + 2 • Message: lpr next. Node: mac. Objects sends Messages • Message: 1 + 2 • Message: lpr next. Node: mac. Node • Message: Packet send: 'This packet travelled to' to: #lpr – receiver : 1 (an instance of Small. Integer) – selector: #+ – arguments: 2 – receiver lpr (an instance of Lan. Printer) – selector: #next. Node: – arguments: mac. Node (an instance of Workstation) – receiver: Packet (a class) – selector: #send: to: – arguments: 'This packet travelled to' and #lpr S. Ducasse 9

Transmitting a Packet | a. Lan packet mac. Node|. . . mac. Node : Transmitting a Packet | a. Lan packet mac. Node|. . . mac. Node : = a. Lan find. Node. With. Address: #mac. packet : = Packet send: 'This packet travelled to the printer' to: #lpr. mac. Node originate: packet. -> mac sends a packet to pc -> pc sends a packet to node 1 -> node 1 sends a packet to node 2 -> node 2 sends a packet to node 3 -> node 3 sends a packet to lpr -> lpr is printing -> this packet travelled to lpr S. Ducasse 10

How to Define a Class (Sq) • Fill the template: Name. Of. Superclass subclass: How to Define a Class (Sq) • Fill the template: Name. Of. Superclass subclass: #Name. Of. Class instance. Variable. Names: 'inst. Var. Name 1' class. Variable. Names: 'Class. Var. Name 1 Class. Var. Name 2' pool. Dictionaries: '' category: 'LAN’ • For example to create the class Packet Object subclass: #Packet instance. Variable. Names: 'addressee originator contents ' class. Variable. Names: '' pool. Dictionaries: '' category: 'LAN' S. Ducasse 11

How to Define a Class (VW) Smalltalk define. Class: #Packet superclass: #{Object} indexed. Type: How to Define a Class (VW) Smalltalk define. Class: #Packet superclass: #{Object} indexed. Type: #none private: false instance. Variable. Names: 'addressee originator contents' class. Instance. Variable. Names: '' imports: '' category: 'LAN' S. Ducasse 12

How to define a method? message selector and argument names How to define a method? message selector and argument names "comment stating purpose of message" | temporary variable names | statements Lan. Printer>>accept: the. Packet "If the packet is addressed to me, print it. Otherwise just behave like a normal node. " (the. Packet is. Addressed. To: self) if. True: [self print: the. Packet] if. False: [super accept: the. Packet] S. Ducasse 13

In Java we would write void accept(the. Packet) /*If the packet is addressed to In Java we would write void accept(the. Packet) /*If the packet is addressed to me, print it. Otherwise just behave like a normal node. */ if (the. Packet. is. Addressed. To(this)){ this. print(the. Packet)} else super. accept(the. Packet)} S. Ducasse 14

Summary Define a class Define a method S. Ducasse 15 Summary Define a class Define a method S. Ducasse 15