How Attributes and Methods Differ
Attributes are similar in many ways to methods. Both are part of a
type's definition. Both return an object, and have no defined side
effects. Here are some basic
differences:
- There are no "arguments" supplied when retrieving an attribute.
Methods can have arguments.
- There can be class methods; there currently cannot be class attributes.
- There is always a valid attribute value for every object of a type
for which the attribute is defined. Calling a method on an object for
which the method is defined may return an exception instead of a valid
value in certain cases.
- The value of an attribute depends only on the object, not on any
external data context. The returned value of a method may vary depending
on context, if the semantics allow for this.
(More about attributes.)
(More about methods.)
spok@cs.cmu.edu (Last updated 12-Apr-96)