Types of Classes

In Rexx there are three class types:

An object class (the default) can create instances of the object in response to receiving a NEW or ENHANCED message. An abstract class serves mainly to organize other classes in the hierarchy and define their message interface. A mixin class, through multiple inheritance, is an additional superclass to a class. The mixin class typically possesses methods useful to the class that inherits it, but these must be specifically added because they lie outside the class's normal line of inheritance.

The following sections explain these class types in more detail.

Object Classes

An object class creates instances and provides methods that these instances can use. At the time of its creation, an instance acquires all instance methods of the class it belongs to. If a class adds new methods later, existing instances do not acquire them. Instances created after the new methods do acquire them.

Because classes define methods for their instances, and methods define the variables that instances use, object classes are factories for creating Rexx instances. The Array class is an example of an object class.

Abstract Classes

An abstract class defines methods its subclasses can inherit, but typically has no instances. Rather, it serves to organize other classes in the hierarchy. An abstract class can be used to "filter out" a group of shared methods from a number of subclasses, so they do not have to exist in two places.

An abstract class pushes common elements further up the hierarchy, thus providing a higher level of organization. By filtering out and moving common methods upwards, the abstract class refines the message interface for its subclasses. This lays the groundwork for polymorphism, creating well-defined interfaces for users of the hierarchy. Abstract classes inherit the instance methods of the Class class.

You can create a new abstract class like an object class. You use a simple ::CLASS directive; no options are required. While abstract classes are not intended for creating instances, Rexx does not prevent you from doing so.

Mixin Classes

The mixin class lets you optionally add a set of instance and class methods to one or more other classes using inheritance. You use mixins to extend the scope of a class beyond the usual lines of inheritance defined by the hierarchy. This is like widening a class's inheritance to accept methods from a sibling or cousin, as well as a parent. When a class inherits from more than just its parent superclass, it is called multiple inheritance.

You can add mixin methods to a class by using the INHERIT option on the ::CLASS directive. The class to be inherited must be a mixin class. During class creation and multiple inheritance, subclasses inherit both class and instance methods from their superclasses.

A mixin's first non-mixin superclass is its base class. Any subclass of a mixin's base class can directly or indirectly inherit a mixin; other classes cannot.

To create a new mixin class, you use the ::CLASS directive with the MIXINCLASS option. A mixin class is also an object class and can create its own instances.