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/10 21:52] – small tvcutsemat:tutorial:objects [2007/07/10 22:04] – expanded tvcutsem
Line 124: Line 124:
 In AmbientTalk, all objects delegate messages they cannot understand to the object stored in their field named ''super''. The delegation chain defined by an object and its parent (or chain of parents) determines the scope in which a message is looked up. For ex-nihilo created objects, like the ''Point'' object defined previously, the ''super'' slot is by default set to ''nil''. When a message is finally delegated all the way up to ''nil'', ''nil'' informs the original receiver of the message of the failed lookup, which by default reports the error by means of a ''SelectorNotFound'' exception. In AmbientTalk, all objects delegate messages they cannot understand to the object stored in their field named ''super''. The delegation chain defined by an object and its parent (or chain of parents) determines the scope in which a message is looked up. For ex-nihilo created objects, like the ''Point'' object defined previously, the ''super'' slot is by default set to ''nil''. When a message is finally delegated all the way up to ''nil'', ''nil'' informs the original receiver of the message of the failed lookup, which by default reports the error by means of a ''SelectorNotFound'' exception.
  
-As any field in AmbientTalk objects, the ''super'' field can be dynamically modified.+Because ''super'' is a regular field of an AmbientTalk object (it is just installed by default), it can be dynamically modified, giving rise to //dynamic inheritance//: the ability of objects to change their object inheritance hierarchy at runtime. The SELF language has demonstrated how this language feature can be put to good use for modeling stateful objectsFor example:
  
 <code> <code>
-def openConnection := object: {...}; +def openConnection := object: 
-def closedConnection := object: {...}; +  def send(msg) { ... }; 
-def connection := object: { +}; 
-    def open() { +def closedConnection := object: 
-      super := openConnection.new()+  def send(msg) { ... }; 
-    }; +}; 
-    def close() { +def connection := object: 
-      super := closedConnection.new()+  def init() 
-    }; +    super := closedConnection; 
-  }+  }; 
 +  def open() { 
 +    super := openConnection; 
 +  }; 
 +  def close() { 
 +    super := closedConnection; 
 +  }; 
 +}
 </code> </code>
  
-<note important+In the above example, the ''connection'' object can be in an "open" or "closed" state. Rather than implementing the state-specific behaviour of e.g. the ''send'' method by means of a state variable and an ''if''-test, state-specific methods are implemented in dedicated objects which are dynamically assigned as the parent of the ''connection'' object when it changes state. When ''connection.send(msg)'' is evaluated, the ''send'' message is delegated to the parent, resulting in the application of the method in the correct state. 
-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 field name of the object.+ 
 +<note> 
 +In AmbientTalk, ''self'' and ''super'' indicate the receiver object and the parent respectively. However, ''self'' is a pseudovariable: it is a special keyword, not a variable that can be assigned to. ''super'' on the other hand, denotes a regular field in an object. This is a significant difference with respect to many other object-oriented languages who also treat ''super'' as special keyword. There is, however, reason for this special treatment of ''super'': "super-sends". The repercussions of AmbientTalk's treatment of ''super'' on "super-sends" is discussed below.
 </note> </note>
  
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem