Reusing Classes: Class Libraries

How to:

You can define a class once, but use it in multiple Maintain procedures by storing its definition in a class library. Libraries are a very useful way of reusing source code, enabling you to develop applications more efficiently.

A class library is implemented as an import module (a kind of non-executable procedure) in which you can store class definitions (as well as Maintain functions). After you have created a module, you can import it into each Maintain procedure in which you want to use those classes. For information about creating, editing, and importing modules, see Using Import Modules.

After you have created the import module, simply create new class definitions in the module, or copy existing definitions into the module. You create and edit class definitions in a module in the same way that you create and edit them in a procedure, as described in Defining Classes.

You can nest modules to any depth. For example, if you have two import modules named ClasLib1 and ClasLib2, you can import ClasLib1 into ClasLib2.

Note: A library cannot contain an explicit Top function, and cannot refer to data sources. For example, class definitions in a library cannot contain data source commands (such as NEXT and INCLUDE) and cannot refer to data source stacks.

Top of page

Syntax: How to Import a Class Library Using the MODULE IMPORT Command

You can use the MODULE command to import libraries containing class definitions so that the current procedure can use those classes. Libraries can also contain other source code, such as function definitions. The syntax is

MODULE IMPORT (library_name [, library_name] ... ); 



Is the name of the Maintain procedure that you wish to import as a source code library. Specify its file name without an extension. The file must reside in the path defined by the EDASYNR environment variable.

The MODULE command must immediately follow the MAINTAIN command.