Contents
Page-10
Prev
Next
Page+10
Index
Access to Objects
Access to objects is accomplished by sending
messages to them.
- Retrieving data values:
(send obj x) or obj.getX()
If x is a private data field, getX() is called an
accessor or getter method.
- Setting data values:
(send obj x: 3) or obj.setX(3)
If x is a private data field, setX() is called a
mutator or setter method.
- Requesting actions:
(send obj print) or obj.print()
A message or method call is like a function call, but which function
is called depends on the runtime type (class) of the object.
Wrapping access to a field in accessor methods helps
information hiding, but hurts efficiency.