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 revisionBoth sides next revision
at:tutorial:objects [2007/07/09 21:13] – rewrote tvcutsemat:tutorial:objects [2007/07/09 21:25] – explained tvcutsem
Line 80: Line 80:
 </code> </code>
  
-===== Delegation and cloning ===== +===== Delegation and Cloning =====
-AmbientTalk features object inheritance or delegation. By means of delegation, an object can reuse and extend the defintion of another establishing a parent-child relationship. We identify two kinds of delegation relationships: **IS-A** and **SHARE-A**. These relationships define two different semantics for clonning child objects. Whereas clonning a **IS-A** child also clones its parent, **SHARE-A** child shares the parent of the cloned object (see the figure below).+
  
 +In order to support code reuse and modular extensions between objects, AmbientTalk features //delegation// (also known as object-based inheritance). By means of delegation, an object can reuse and extend the fields and methods of another object by establishing a so-called "parent-child" or "delegate-delegator" relationship.
  
-{{:at:tutorial:isaversussharea.png|:at:tutorial:isaversussharea.png}}+Delegation implies that, if a message is sent to an object, but that object has no definition for the message's selector, then the message is //delegated// to a designated object (often called the //parent// or //delegate//)What is important to note here is that "delegating" a message is not the same as simply "forwarding" the message to the other objectdelegating a message leaves the ''self'' pseudovariable unchanged to the //original// receiver of the message.
  
- +AmbientTalk distinguishes between **two kinds** of delegation relationships,**IS-A** and **SHARES-A**, each denoting different kind of object extension. An **IS-A** delegation relationship between two objects signifies that the child object "is-a" kind of parent object, with the implicit assumption that such a child object cannot exist without its parentAs an example, consider the following code (don't worry about the meaning of ''^'' yet):
-The following code shows how to extend objects with a **IS-A** relationship. It uses the ''extend: with:'' language construct.+
  
 <code> <code>
-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
-    }+
   }   }
 +}
 </code> </code>
 +
 +In this example, ''Point3D'' delegates
 +
 +These relationships define two different semantics for clonning child objects. Whereas clonning a **IS-A** child also clones its parent, **SHARE-A** child shares the parent of the cloned object (see the figure below).
 +
 +
 +{{:at:tutorial:isaversussharea.png|:at:tutorial:isaversussharea.png}}
 +
 +
 +The following code shows how to extend objects with a **IS-A** relationship. It uses the ''extend: with:'' language construct.
 +
 +
  
 The following code shows how to extend objects with a **SHARE-A** relationship. It uses the ''share: with:'' language construct. The following code shows how to extend objects with a **SHARE-A** relationship. It uses the ''share: with:'' language construct.
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem