The ::CLASS directive causes the interpreter to create a Rexx class.
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 is a literal
string or an optionally
namespace-qualified
symbol that is taken as a constant. 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.
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 an optionally
namespace-qualified
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.
The
mclass
is a literal string or an optionally
namespace-qualified
symbol that is taken as a constant. 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
ABSTRACT option, the class will be marked as an
abstract class.
Trying to create an instance of an abstract class will raise an error.
Only subclasses of abstract classes will allow to create instances from.
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.
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 optionally
namespace-qualified
symbols that are taken as constants.
If you omit the
INHERIT option, the class inherits only from
sclass.
Example 3.6. 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.7. 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.
You can specify the options
METACLASS,
MIXINCLASS,
SUBCLASS, and
PUBLIC in any order.
If you specify
INHERIT, it must be the last option.