Skip to main content

Software > Software Development > IBM REXX Family >

NetRexx

Technical detail

Minor and dependent classes

This section describes minor classes and dependent classes – features supported by the NetRexx reference implementation which are expected to be included in some future NetRexx language definition, should there be an updated definition.

The sections here are:

Minor classes

A minor class in NetRexx is a class whose name is qualified by the name of another class, called its parent. This qualification is indicated by the form of the name of the class: the short name of the minor class is prefixed by the name of its parent class (separated by a period). For example, if the parent is called Foo then the full name of a minor class Bar would be written Foo.Bar. The short name, Bar, is used for the name of any constructor method for the class; outside the class it can only be used to identify the class in the context of the parent class (or from children of the minor class, see below).

The names of minor classes may be used in exactly the same way as other class names (types) in programs. For example, a property might be declared and initialized thus:

  abar=Foo.Bar null   -- this has type Foo.Bar

or, if the class has a constructor, perhaps:

  abar=Foo.Bar()      -- constructs a Foo.Bar object

Minor classes must be in the same program (and hence in the same package) as their parent. They are introduced by a class instruction that specifies their full name, for example:

  class Foo.Bar extends SomeClass

Minor classes must immediately follow their parent class.[1]

Minor classes may have a parent which is itself a minor class, to any depth; the name and the positioning rules are extended as necessary. For example, the following classes might exist in a program:

  class Foo    class Foo.Bar      class Foo.Bar.Nod      class Foo.Bar.Pod    class Foo.Car

As before, the children of Foo.Bar immediately follow their parent. The list of children of Foo can be continued after the children of Foo.Bar have all been specified.

Note that the short name (last part of the name) of a minor class may not be the same as the short name of any of its parents (a class Foo.Bar.Foo or a class Foo.Bar.Bar would be in error, for example). This allows minor classes to refer to their parent classes by their short name without ambiguity.

Constructing objects in minor classes

A parent class can construct an object of a child class in the usual manner, by simply specifying its constructor (identified by its short name, full name, or qualified name). For example, a method in the Foo.Bar class above could construct an object of type Foo.Bar.Nod using:

  anod=Nod()

(assuming the Foo.Bar.Nod class has a constructor that takes no arguments).

Similarly, minor classes can refer to the types and constructors of any of its parents by simply using their short names. Hence, the Foo.Bar.Nod class could construct objects of its parents' types thus:

  abar=Bar()  afoo=Foo()

(again assuming the parent classes have constructors that take no arguments).

Classes other than the parent or an immediate child must use the full name (if necessary, qualified by the package name) to refer to a minor class or its constructor.

Dependent classes

As described in the last section, minor classes provide an enhanced packaging (naming) mechanism for classes, allowing classes to be structured within packages. A stronger link between a child class and its parent is indicated by the modifier keyword dependent on the child class, which indicates that the child is a dependent class. For example:

  class Foo.Dep dependent extends SomeClass    method Dep   -- this is the constructor

An object constructed from a dependent class (a dependent object) is linked to the context of an object of its parent type (its parent object). The linkage thus provided allows the child object simplified access to the parent object and its properties.

In the example, an object of type Foo.Dep can only be constructed in the context of a parent object, which must be of type Foo.

Constructing dependent objects

A parent class can construct a dependent object in the same way as when constructing objects of other child types; that is, by simply specifying its constructor. In this case, however, the current object (this) becomes the parent object of the newly constructed object. For example, a method in the Foo class above could construct a dependent object of type Foo.Dep using:

  adep=Dep()

(assuming the Dep class has a constructor that takes no arguments).

In general, for a class to construct an object from a dependent class, it must have a reference to an object of the parent class (which will become the parent of the new object), and the constructor must be called (by its short name) in the context of that parent object. For example:

  parentObject=Foo()  adep=parentObject.Dep()

(In the same way, the first example could have been written:

  adep=this.Dep()

within the parent class the this. is implied.)

In order to subclass a dependent class, the constructor of the dependent class must be invoked by the subclass constructor in a similar manner. In this case, a qualified call to the usual special constructor super is used, for example:

  class ASub extends Foo.Dep    method Asub(afoo=Foo)      afoo.super()

The qualifier (afoo in the example) must be either the name of an argument to the constructor, or the special word parent (if the classes share a common parent class), or the short name of a parent class followed by .this (see below). The call to super must be the first instruction in the method, as usual, and it must be present (it will not be generated automatically by the compiler).

Access to parent objects and their properties

Dependent classes have simplified access to their parent objects and their properties. In particular:

  • The special word parent may be used to refer to the parent object of the current object. It may appear alone in a term, or at the start of a compound term. It can only be used in non-static contexts in a dependent class.
  • In general, any of the objects in the chain of parents of a dependent object may be referred to by qualifying the special word this with the short name of the parent class. For example, extending the previous example, if the class Foo.Dep.Ent was a dependent class it could contain references to Foo.this (the parent of its parent) or Dep.this (the latter being the same as specifying parent). If preferred, the full name or the fully qualified name of the parent class may be used instead of the short name.
    Like parent, this construct can only be used at the start of a term in non-static contexts in a dependent class.
  • As usual, properties external to the current class must always be qualified in some way (for example, the prefix parent. can be used in a term such as parent.aprop).

Restrictions

Minor classes may have any of the attributes (public, interface, etc.) of other classes, and behave in every way like other classes, with the following restrictions:

  • If a class is a static class (that is, it contains only static or constant properties and methods) then any children cannot be dependent classes (because no object of the parent class can be constructed). Similarly, interface classes and abstract classes cannot have dependent classes.
  • Dependent classes may not be interfaces.
  • Dependent classes may not contain static or constant properties (or methods).[2] These must be placed in a parent which is not a dependent class.
  • Minor classes may be public only if their parent is also public. (Note that this is the only case where more than one public class is permitted in a program.) In general: a minor class cannot be more visible than its parent.

Footnotes:

[1]  This allows compilers that generate Java source code to preserve line numbering.

[2]  This restriction allows compilation for the Java platform.

Supplement to The NetRexx Language by Mike Cowlishaw, mfc@uk.ibm.com (ISBN 0-13-806332-X, 197pp, Prentice-Hall, 1997).

 

 

 Table of contents Next
We're here to help
Easy ways to get the answers you need.
Request a quote
E-mail IBM

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