Objects with Their Own Unique Scope

The methods and variables used by instances in a class are usually found at the class level. But sometimes an instance differs in some way from the others in its class. It may perform an additional action or require some unique handling. In this case one or more methods and related variables can be added directly to the instance. These methods and variables form a totally separate scope, independent of the more-typical class scopes found throughout the rest of the hierarchy.

Methods can be added directly to an instance's collection of object methods using SETMETHOD, a method of the Object class. All subclasses of the Object class inherit SETMETHOD. Alternately, the Class class provides an ENHANCED method that lets you create new instances of a class, whose object methods are the instance methods of its class, but "enhanced" with additional collection methods.


[Back: Objects with a Class Scope]
[Next: More about Methods]