Now that you know about classes and how to create them, we'll cover the mechanics of using objects and methods in more detail. First, here is a quick refresher.
We have said that a REXX object consists of:
Sending a message to an object causes it to perform a related action. The method whose name matches the message performs the action. The message is the interface to the object, and with information hiding, only methods that belong to an object can access its variables.
Objects are grouped hierarchically into classes. The class at the very top of the hierarchy is the Object class. Everything below it in the hierarchy belongs to the Object class and is therefore an object. As a result, all classes are objects.
In a class hierarchy, classes, superclasses, and subclasses are relative to one another. Unless designated otherwise, any class directly above a class in the hierarchy is a superclass. And any class below is a subclass.
From a class object you can create instances of the class. Instances are merely similar objects that fit the template of the class; they belong to the class, but are not classes themselves. Instances are the most basic, most elemental of objects.
Both classes and their instances are objects. All objects contain variables and methods, and so this is true for class objects. The methods a class provides for use by its various instances are called instance methods. In effect, these define which messages an instance can respond to. Instance methods are by far the most common methods in REXX, and here we simply call them "methods."
The methods available to the class object itself are called class methods.
(They are actually the instance methods of the Class class.) They define
messages that only the class--and not its instances--can respond to. Class
methods generally exist to create instances and are much less common.
When referring to these rarer methods, we will be sure to identify them
specifically as "class methods." Instancemethodsandclassmethods
Instance methods Class methods
---------------- -------------
ADD CREATE_INSTANCE
SUBTRACT
┌───── MULTIPLY Number
│ DIVIDE class ──────────┘
│ │
│ ┌──┬──┬──┼──┬─────┐
│ │ │ │ │ │ │
└──────────────── 1 2 3 4 5 ... n
instances