The "Class" Class

Within its class hierarchy REXX includes a class for generating new classes, and this the Class class. If a class is like a factory for producing instances, Class is like a factory for producing factories. Class is the parent of every new class in the hierarchy, and these all inherit Class-like characteristics. The Class-like characteristics take the form of methods and related variables, which reside in Class, to be used by all classes.

A class that can be used to create another class is called a metaclass. The Class class is unique among REXX classes in that it is the only metaclass REXX provides (see Metaclasses). As such, Class's methods not only make new classes, they make methods for use by the new class and its instances. They also make methods that only the new class itself can use, apart from its instances. These are called class methods. They give a new class some powers that its instances are denied.

Because each instance of Class is another class, or factory, that factory inherits Class's instance methods as class methods. Think of the instance methods of the Class factory as factory-running actions. Thus if Class generates a Pizza factory instance, the factory-running actions (Class's instance methods) become the class methods of the Pizza factory. Factory operations are class methods, and any new methods created to manipulate pizzas would be instance methods:
How subclasses inherit instance methods from the Class class

┌──────────────────────────────────────



"Class" class


│ Class's class methods
│ ---------------------
│ Factory-creating
│ actions

│ Class's instance methods ───┐
│ ------------------------ │
│ Factory-running │
│ actions │
│ │
│ │
Pizza class │

Pizza's class methods ──┘
---------------------
Factory-running
actions

Pizza's instance methods
------------------------
pizza-making
actions



As a programmer, you will typically create classes by using directives, rather than the methods of the Class class. In particular, you'll use the ::CLASS directive, described later in this section. The ::CLASS directive is a kind of REXX clause that allows class definitions to be saved permanently, in a file, where they can be reused by other programs. Creating classes "on the fly," by using Class methods sent as messages, is not recommended when permanency or reuse is required. At any rate, directives have class-creating powers similar to the Class methods.


[Back: The Object Class]
[Next: REXX Classes: The Big Picture]