Chapter 5. The Basics of Classes

Table of Contents
Rexx Classes for Programming
Rexx Classes for Organizing Objects
Rexx Classes: The Big Picture
Creating Your Own Classes Using Directives
Defining an Instance
Types of Classes

Similar objects in Rexx are grouped into classes, forming a hierarchy. Rexx gives you a basic class hierarchy to start with. All of the classes in the hierarchy are described in detail in the Open Object Rexx: Reference. The following list shows the classes Rexx provides (there may be others in the system). The classes indented are subclasses. Classes in the list that are described later in this chapter are printed in bold:

    Object
    Alarm
    Class
    Collection classes
        Array
        List
        Queue
        CircularQueue
        IdentityTable
        Table
        Set
        Directory
        Stem
        Relation
        Bag
    Message
    Method
    Routine
    Package
    Monitor
    Stream
    String
    Supplier

Rexx Classes for Programming

The classes Rexx supplies provide the starting point for object-oriented programming. Some key classes that you are likely to work with are described in the following sections.

The Alarm Class

The Alarm class is used to create objects with timing and notification capability. An alarm object is able to send a message to an object at any time in the future, and until then, you can cancel the alarm.

The Collection Classes

The collection classes are used to manipulate collections of objects. A collection is an object that contains a number of items, which can be any objects. These manipulations might include counting objects, organizing them, or assigning them a supplier (for example, to indicate that a specific assortment of baked goods is supplied by the Pie-by-Night Bakery).

Rexx includes classes, for example, for arrays, lists, queues, tables, and directories. Each item stored in a Rexx collection has an associated index that you can use to retrieve the item from the collection with the AT or [] (left and right bracket) methods, and each collection defines its own acceptable index types:

Array

A sequenced collection of objects ordered by whole-number indexes.

List

A sequenced collection that lets you add new items at any position in the sequence. A list generates and returns an index value for each item placed in the list. The returned index remains valid until the item is removed from the list.

Queue

A sequenced collection of items ordered as a queue. You can remove items from the head of the queue and add items at either its tail or its head. Queues index the items with whole-number indexes, in the order in which the items would be removed. The current head of the queue has index 1, the item after the head item has index 2, up to the number of items in the queue.

Table

A collection of indexes that can be any object. For example, string objects, array objects, alarm objects, or any user-created object can be a table index. The Table class determines an index match by using the == comparison method to test for strict equality. A table contains no duplicate indexes.

Directory

A collection of character string indexes. Indexes are compared using the string == comparison method to test for strict equality.

Relation

A collection of indexes that can be any object (as with the Table class). A relation can contain duplicate indexes.

Set

A collection where the indexes are equal to the values. Set indexes can be any object (as with the Table class) and each index is unique.

Bag

A collection where the index is equal to the value. Bag indexes can be any object (as with the Table class) and each index can appear more than once.

The Message Class

Message objects allow you to run concurrently methods on other threads or to invoke dynamically calculated messages. Methods of for this class are used, for example, to start a message on another thread, to notify the sender object when an error occurs or when message processing is complete, or to return the results of that processing to the sender or to some other object.

The Monitor Class

The Monitor class provides a way to forward messages to a specified destination. The Monitor creates a proxy that can route dynamically route messages to different destinations. Monitor methods change or restore a destination object.

The Stem Class

A stem variable is a symbol that must start with a letter and end with a period, like "FRED." or "A.". The value of a stem variable is a Stem object. A stem object is a collection of unique character string indexes. Stem objects are automatically created when a Rexx stem variable or Rexx compound variable is used. In addition to the items assigned to the collection indexes, a stem object also has a default value that is used for all uninitialized indexes of the collection.

The Stream Class

Input and output streams let Rexx communicate with external objects, such as people, files, queues, serial interfaces, displays, and networks. In programming there are many stream actions that can be coded as methods for manipulating the various stream objects. These methods and objects are organized in the Stream class.

The methods are used to open streams for reading or writing, close streams at the end of an operation, move the line-read or line-write position within a file stream, or get information about a stream. Methods are also provided to get character strings from a stream or send them to a stream, count characters in a stream, flush buffered data to a stream, query path specifications, time stamps, size, and other information from a stream, or do any other I/O stream manipulation (see Input and Output for examples).

The String Class

Strings are data values that can have any length and contain any characters. They are subject to logical operations like AND, OR, exclusive OR, and logical NOT. Strings can be concatenated, copied, reversed, joined, and split. When strings are numeric, there is the need to perform arithmetic operations on them or find their absolute value or convert them from binary to hexadecimal, and vice versa. All this and more can be accomplished using the String class of objects.

The Supplier Class

All collections have suppliers The Supplier class is used to enumerate items that a collection contained when the supplier was created. The supplier gives access to each index/value pair stored in the collection as a sequence.