at:tutorial:objects
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:objects [2007/07/09 21:03] – * tvcutsem | at:tutorial:objects [2007/07/09 21:25] – explained tvcutsem | ||
---|---|---|---|
Line 45: | Line 45: | ||
===== Cloning and instantiation ===== | ===== Cloning and instantiation ===== | ||
- | As said before in this section, AmbientTalk objects are created [[objects# | + | As noted above, AmbientTalk objects are created [[# |
< | < | ||
- | > def anotherPoint := point.new(2,3) | + | def anotherPoint := Point.new(2,3) |
</ | </ | ||
- | Every object understands the message '' | + | Every object understands the message '' |
- | + | ||
- | AmbientTalk also provides a '' | + | |
< | < | ||
- | > def clonedPoint | + | > anotherPoint.x |
+ | >> 2 | ||
+ | > Point.x | ||
+ | >> 0 | ||
+ | > anotherPoint.x | ||
+ | >> nil | ||
+ | > Point.x | ||
+ | >> 0 | ||
</ | </ | ||
- | ===== Delegation and cloning ===== | + | < |
- | AmbientTalk | + | AmbientTalk' |
+ | </ | ||
+ | AmbientTalk also provides a '' | ||
- | {{:at:tutorial: | + | < |
+ | def clonedPoint | ||
+ | > clonedPoint.x | ||
+ | >> 0 | ||
+ | > clonedPoint.x | ||
+ | >> nil | ||
+ | > Point.x | ||
+ | >> 0 | ||
+ | </ | ||
+ | ===== Delegation and Cloning ===== | ||
- | The following code shows how to extend | + | In order to support code reuse and modular extensions between |
+ | |||
+ | 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, | ||
< | < | ||
- | > 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