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/06/29 14:31] jorgeat:tutorial:objects [2007/06/29 14:58] jorge
Line 91: Line 91:
  
 ===== First-class Delegation ===== ===== First-class Delegation =====
 +
  
 ===== Encapsulation ===== ===== Encapsulation =====
 +In AmbientTalk, all fields and methods are "public" via selection. Still, a field or method can be made "private" by means of lexical scoping. The following code shows the definition of an object inside the definition of a function. The fields and methods of this object cannot be accessed directly from outside the funuction.
 +
 +<code>
 +> def makeObject(hidden) {
 +    object: {
 +      def foo() { /* use hidden */ }
 +    }
 +  }
 +</code>
 +
 +Due to the encapsulation of this object the following instruction fails:
  
 +<code>
 +> makeObject(5).hidden;
 +>>Lookup failure : selector hidden could not be found in 
 +  <object:5068254>
 +</code>
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem