The ::CLASS directive causes the interpreter to create a Rexx class.
>>-::CLASS--classname--+----------------------+------------------->
+-METACLASS--metaclass-+
.-SUBCLASS--Object---. +-PRIVATE-+
>--+--------------------+--+---------+--+-------------------+--;--><
+-MIXINCLASS--mclass-+ +-PUBLIC--+ +-INHERIT--iclasses-+
+-SUBCLASS--sclass---+
The ::CLASS directive creates a Rexx class named classname. The classname is a literal string or symbol that is taken as a constant. The created class is available to programs through the Rexx environment symbol .classname. The classname acquires all methods defined by subsequent ::METHOD directives until the end of the program or another ::CLASS directive is found. Only null clauses (comments or blank lines) can appear between a ::CLASS directive and any following directive instruction or the end of the program. Only one ::CLASS directive can appear for classname in a program.
If you specify the METACLASS option, the instance methods of the
metaclass class become class methods of the
classname class. (See
Chapter 4, Objects and Classes .) The
metaclass and
classname are literal strings or symbols that are taken as constants. In the search order for methods, the metaclass methods precede inherited class methods and follow any class methods defined by ::METHOD directives with the CLASS option.
If you specify the PUBLIC option, the class is visible beyond its containing Rexx program to any other program that references this program with a ::REQUIRES directive. (See
Section 3.6, “::REQUIRES”.) If you do not specify the PUBLIC option, the class is visible only within its containing Rexx program. All public classes defined within a program are used before PUBLIC classes created with the same name.
If you specify the SUBCLASS option, the class becomes a subclass of the class sclass for inheritance of instance and class methods. The sclass is a literal string or symbol that is taken as a constant.
If you specify the MIXINCLASS option, the class becomes a subclass of the class mclass for inheritance of instance and class methods. You can add the new class instance and class methods to existing classes by using the INHERIT option on a ::CLASS directive or by sending an INHERIT message to an existing class. If you specify neither the SUBCLASS nor the MIXINCLASS option, the class becomes a non-mixin subclass of the Object class.
If you specify the INHERIT option, the class inherits instance methods and class methods from the classes
iclasses in their order of appearance (leftmost first). This is equivalent to sending a series of INHERIT messages to the class object, with each INHERIT message (except the first) specifying the preceding class in
iclasses as the
classpos argument. (See
Section 5.1.2.9, “inherit” .) As with the INHERIT message, each of the classes in
iclasses must be a mixin class. The
iclasses is a whitespace-separated list of literal strings or symbols that are taken as constants. If you omit the INHERIT option, the class inherits only from
sclass.
Example:
Example 3.4. CLASS directive
::class rectangle
::method area /* defined for the RECTANGLE class */
expose width height
return width*height
::class triangle
::method area /* defined for the TRIANGLE class */
expose width height
return width*height/2
The ::CLASS directives in a program are processed in the order in which they appear. If a ::CLASS directive has a dependency on ::CLASS directives that appear later in the program, processing of the directive is deferred until all of the class's dependencies have been processed.
Example 3.5. CLASS directive deferred processing
::class savings subclass account /* requires the ACCOUNT class */
::method type
return "a Savings Account"
::class account
::method type
return "an Account"
The Savings class in the preceding example is not created until the Account class that appears later in the program has been created.
Notes:
You can specify the options METACLASS, MIXINCLASS, SUBCLASS, and PUBLIC in any order.
If you specify INHERIT, it must be the last option.