User Tools

Site Tools


at:tutorial:objects

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
at:tutorial:objects [2007/07/02 13:29] jorgeat:tutorial:objects [2007/07/04 16:29] jorge
Line 67: Line 67:
 > def point3D := extend: point with: { > def point3D := extend: point with: {
     def z := 0;     def z := 0;
-    def sumofsquares() { +    def sumOfSquares() { 
-      super.sumofsquares() + z*z+      super^sumOfSquares() + z*z
     }     }
   }   }
Line 78: Line 78:
 > def point3D := share: point with: { > def point3D := share: point with: {
     def z := 0;     def z := 0;
-    def sumofsquares() { +    def sumOfSquares() { 
-      super.sumofsquares() + z*z+      super^sumOfSquares() + z*z
     }     }
   }   }
Line 88: Line 88:
  
 <code> <code>
-> def OpenConnection := object: {...}; +> def openConnection := object: {...}; 
-    def ClosedConnection := object: {...}; +def closedConnection := object: {...}; 
-    def Connection := object: { +def connection := object: { 
-      def open() { +    def open() { 
-        super := OpenConnection.new();+      super := openConnection.new();
     };     };
     def close() {     def close() {
-      super := ClosedConnection.new();+      super := closedConnection.new();
     };     };
   }   }
 </code> </code>
 +
 +<note important>
 +In AmbientTalk, ''self'' and ''super'' indicate the current object and its parent respectively. While the former corresponds to a language keyword the latter is just a field name of the object.
 +</note>
  
 ===== First-class delegation ===== ===== First-class delegation =====
-AmbientTalk provides an explicit delegation operator ''^''. The code below illustrates the use of this operator in the implementation of the ''init'' method of the ''point3D'' object.+AmbientTalk provides an explicit delegation operator ''^'' (the "caret" or "hat" symbol). The code below illustrates the use of the ''^'' operator in the implementation of the ''init'' method of the ''point3D'' object.
  
 <code> <code>
Line 113: Line 117:
 </code> </code>
  
-A message sent to an object using this symbol (e.g. to the parent object in the example above) will first look for the method that matches the selector indicated in the message in this object (and its parents) and then execute the method body in the lexical scope of the message sender.+A message sent to an object using the ''^'' symbol (e.g. to the parent object in the example above) will start the method lookup in this object (and its parents) and then execute the method body in the lexical scope of the message sender (''self'' is bound to the message sender). 
 + 
 +<note important> 
 +The delegation operator does not have the same semantics as the dot notation. A message sent to ''super'' using the dot notation will not only start the method lookup in the object bound the ''super'' field but also bind the ''self'' pseudo variable to this object. 
 +</note>
  
 ===== Encapsulation ===== ===== Encapsulation =====
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem