Class File

With classes you can make several kinds of non-procedural declarations. The first line in a class declares the name of the class and an optional structure or enumerated type declaration.

   class Point is X    double, Y    double     :Declare a structure.
   class Color in Red, Green, Blue, Yellow     :Declare an enumeration.
   class Utility                               :Class with no type declaration

Subsequently you can make additional Type declarations.

   type Line  is Begin  Point, End  Point      :Declare a structure.
   type Shade in Light, Medium, Dark           :Declare an enumeration.

Classes can also contain Global variable declarations. By default Globals can be modified only by methods that are members of the class. They can still be read by any other method. You can permit both read and write access from any method by coding a lead plus sign.

   global Limit    word         :Write only by members; read by any method.
   global +Text    string       :Read and write from any method.

A class can also be designated to be private. Globals in these classes can only be be accessed by procedures in the private class or from neighboring classes. A neighboring class file is in the same directory as the private class or in the directory above it.

To gain access to a Global from a procedure include a Use or Alter declaration in the procedure. A Use declaration is for read-only access and Alter allows write access as well. Classes can also have Use declarations to gain read access read Globals declared in other class.

     use Point/Limit            :Read the Limit global in the Point class.
   alter Point/Text             :Read and write access to the Text global.

By default, when a method belongs to a class it gains implicit access to any globals declared in the class; no Use declaration is needed. Any Use or Alter declaration for a Global with the same name will override this default.

Additional facilities in classes allow for inheritence, virtual procedures, and generic templates. When a class is inherited its primary structure or enumeration is merged into the class doing the inheriting. Its member methods are also merged in.

Generic templates allow classes to be parameterized at compile time. Most commonly Generics allow the same method to operate on multiple types.

Precondition and Postcondition

Build a Program