::CLASS

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---+

Notes:

  1. You can specify the options EXTERNAL, METACLASS, MIXINCLASS, SUBCLASS, and PUBLIC in any order.

  2. If you specify INHERIT, it must be the last option.

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 EXTERNAL option, the class is created using information derived from an external source named extname. The extname is a literal string.

If you specify the METACLASS option, the instance methods of the metaclass class become class methods of the classname class. (See 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 ::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 INHERIT .) As with the INHERIT message, each of the classes in iclasses must be a mixin class. The iclasses is a blank-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:

::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:

::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.

Note: If you specify the same ::CLASS classname more than once in different programs, the last one is used. Using more than one ::CLASS classname in the same program produces an error.