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/02 13:35] – jorge | at:tutorial:objects [2007/07/09 21:00] – * tvcutsem | ||
---|---|---|---|
Line 4: | Line 4: | ||
In AmbientTalk, | In AmbientTalk, | ||
classes. Rather, they are either created ex-nihilo or by cloning | classes. Rather, they are either created ex-nihilo or by cloning | ||
- | and adapting existing objects, | + | and adapting existing objects, |
The following code illustrates the ex-nihilo creation of an object: | The following code illustrates the ex-nihilo creation of an object: | ||
< | < | ||
- | > def point := object: { | + | def Point := object: { |
- | def x := 0; | + | def x := 0; |
- | def y := 0; | + | def y := 0; |
- | def init(aX,aY) { | + | def init(aX,aY) { |
- | x := aX; | + | x := aX; |
- | y := aY; | + | y := aY; |
- | }; | + | }; |
- | def sumOfSquares() { x*x + y*y }; | + | def sumOfSquares() { x*x + y*y }; |
- | } | + | } |
</ | </ | ||
- | As all definitions in AmbientTalk, objects, fields and methods are defined using the **def** keyword. Fields are defined using a '' | + | The above code defines an // |
- | < | + | In the example above, the state of the point object is composed of '' |
- | AmbientTalk not only supports traditional canonical syntax (e.g. '' | + | |
+ | < | ||
+ | As already explained in the [[at: | ||
+ | |||
+ | For Smalltalk/ | ||
</ | </ | ||
- | |||
- | In the example above, the state of the '' | ||
===== Sending messages ===== | ===== Sending messages ===== | ||
Line 99: | Line 101: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | <note important> | ||
+ | In AmbientTalk, | ||
+ | </ | ||
===== First-class delegation ===== | ===== First-class delegation ===== | ||
- | AmbientTalk provides an explicit delegation operator '' | + | AmbientTalk provides an explicit delegation operator '' |
< | < | ||
Line 113: | Line 119: | ||
</ | </ | ||
- | 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 | + | A message sent to an object using the '' |
+ | |||
+ | <note warning> | ||
+ | The delegation operator does not have the same semantics as the dot notation. A message sent to '' | ||
+ | </ | ||
===== Encapsulation ===== | ===== Encapsulation ===== |
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem