Skip to main content

Software > Software Development > IBM REXX Family >

NetRexx

Technical detail

Class instruction

class name [visibility] [modifier] [binary]

            [extends classname]

            [uses useslist]

            [implements interfacelist];

where visibility is one of:

  private
public

and modifier is one of:

  abstract
final
interface

and useslist and interfacelist are lists of one or more classnames, separated by commas.

The class instruction is used to introduce a class, as described in the sections Types and Classes and Program structure, and define its attributes. The class must be given a name, which must be different from the name of any other classes in the program. The name, which must be a non-numeric symbol, is known as the short name of the class.

A classname can be either the short name of a class (if that is unambiguous in the context in which it is used), or the qualified name of the class -- the name of the class prefixed by a package name and a period, as described under the package instruction.

The body of the class consists of all clauses following the class instruction (if any) until the next class instruction or the end of the program.

The visibility, modifier, and binary keywords, and the extends, uses, and implements phrases, may appear in any order.

Visibility

Classes may be public or private:

  • A public class is visible to (that is, may be used by) all other classes.
  • A private class is visible only within same program and to classes in the same package.

A program may have only one public class, and if no class is marked public then the first is assumed to be public (unless it is explicitly marked private).

Modifier

Most classes are collections of data (properties) and the procedures that can act on that data (methods); they completely implement a datatype (type), and are permitted to be subclassed. These are called standard classes. The modifier keywords indicate that the class is not a standard class -- it is special in some way. Only one of the following modifier keywords is allowed:

abstract

An abstract class does not completely implement a datatype; one or more of the methods that it defines (or which it inherits from classes it extends or implements) is abstract -- that is, the name of the method and the types of its arguments are defined, but no instructions to implement the method are provided.

Since some methods are not provided, an object cannot be constructed from an abstract class. Instead, the class must be extended and any missing methods provided. Such a subclass can then be used to construct an object.

Abstract classes are useful where many subclasses can share common data or methods, but each will have some unique attribute or attributes (data and/or methods). For example, some set of geometric objects might share dimensions in X and Y, yet need unique methods for calculating the area of the object.

final

A final class is considered to be complete; it cannot be subclassed (extended), and all its methods are considered complete.[1] 

interface

An interface class is an abstract class that contains only abstract method definitions and/or constants. That is, it defines neither instructions that implement methods nor modifiable properties, and hence cannot be used to construct an object.

Interface classes are used by classes that claim to implement them (see the implements keyword, described below). The primary difference between abstract and interface classes is that the former may have methods which are not abstract, and hence can only be subclassed (extended), whereas the latter are wholly abstract and may only be implemented.

Interface classes may not be private; any properties in an interface class are both public and constant.

Binary

The keyword binary indicates that the class is a binary class. In binary classes, literal strings and numeric symbols are assigned native string or binary (primitive) types, rather than NetRexx types, and native binary operations are used to implement operators where possible. When binary is not in effect (the default), terms in expressions are converted to NetRexx types before use by operators. The section Binary values and operations describes the implications of binary classes in detail.

Extends

Classes form a hierarchy, with all classes (except the top of the tree, the Object[2]  class) being a subclass of some other class. The extends keyword identifies the classname of the immediate superclass of the new class -- that is, the class immediately above it in the hierarchy. If no extends phrase is given, the superclass is assumed to be Object (or null, in the case where the current class is Object).

Uses

The uses keyword introduces a list of the names of one or more classes that will be used as a source of constant (or static) properties and/or methods.

When a term starts with a symbol, method call, or indexed reference that is not known in the current context, each class in the useslist and its superclasses are searched (in the order specified in the useslist) for a constant or static method or property that matches the item. If found, the method or property is used just as though explicitly qualified by the name of the class in which it was found.

The uses mechanism affects only the syntax of terms in the current class; it is not inherited by subclasses of the current class.

Implements

The implements keyword introduces a list of the names of one or more interface classes (see above). These interface classes are then known to (inherited by) the current class, in the order specified in the interfacelist. Their methods (which are all abstract) and constant properties act as though part of the current class, unless they are overridden (hidden) by a method or constant of the same name in the current class.

If the current class is not an interface class then it must implement (provide non-abstract methods for) all the methods inherited from the interface classes in the implements list.

Interface classes, therefore, can be used to:

  1. Define a common set of methods (possibly with associated constants) that will be implemented by other classes.
  2. Conveniently package collections of constants for use by other classes.

The implements list may not include the superclass of the current class.

Footnotes:

[1]  This modifier is provided for consistency with other languages, and may allow compilers to improve the performance of classes that refer to the final class. In many cases it will reduce the reusability of the class, and hence should be avoided.

[2]  In the reference implementation, java.lang.Object.

 

 

 

PreviousTable of contents Next
We're here to help
Easy ways to get the answers you need.
E-mail us

or call us at
877-426-3774
Priority code:
104CBW67