at:tutorial:objects
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
at:tutorial:objects [2007/07/09 21:13] – rewrote tvcutsem | at:tutorial:objects [2007/07/09 21:25] – explained tvcutsem | ||
---|---|---|---|
Line 80: | Line 80: | ||
</ | </ | ||
- | ===== 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: | + | |
+ | In order to support code reuse and modular extensions between objects, AmbientTalk features // | ||
- | {{: | + | Delegation implies that, if a message is sent to an object, but that object has no definition for the message' |
- | + | AmbientTalk distinguishes between **two kinds** of delegation relationships, | |
- | The following code shows how to extend objects with a **IS-A** relationship. | + | |
< | < | ||
- | > def point3D | + | def Point3D |
- | def z := 0; | + | def z := 0; |
- | def sumOfSquares() { | + | def sumOfSquares() { |
- | super^sumOfSquares() + z*z | + | super^sumOfSquares() + z*z |
- | } | + | |
} | } | ||
+ | } | ||
</ | </ | ||
+ | |||
+ | In this example, '' | ||
+ | |||
+ | 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). | ||
+ | |||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | The following code shows how to extend objects with a **IS-A** relationship. It uses the '' | ||
+ | |||
+ | |||
The following code shows how to extend objects with a **SHARE-A** relationship. It uses the '' | The following code shows how to extend objects with a **SHARE-A** relationship. It uses the '' |
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem