Try OpenEdge Now
skip to main content
Object-oriented Programming
Getting Started with Classes, Interfaces, and Objects : Class definition files and object type names : Comparing class definition files and procedure source files
 

Comparing class definition files and procedure source files

A class definition file has many similarities to a procedure file but there are some differences that justify their having different source filename extensions. Both class definition files and procedure files define a main block in which state and behavior are defined. Procedure files have no rigid syntax, and can begin with any ABL statement. However, the main block of a class definition file must be defined either between a starting CLASS statement and a terminating END CLASS statement (the CLASS block) or between a starting INTERFACE statement and a terminating END INTERFACE statement (the INTERFACE block).
The CLASS or INTERFACE statement is necessary to specify the object type name and other information required to support the class or interface definition. If a class definition file (with the .cls extension) does not contain a CLASS or INTERFACE statement, ABL generates a compilation error. Both class definition files and procedure files can have USING statements that allow you to specify unqualified class and interface names for the object types that they reference.
Procedure files allow data elements scoped to the procedure file to be defined in the main block using DEFINE statements outside of internal procedure and user-defined function definitions. Similarly, class definition files allow data members and properties scoped to the class file to be defined using DEFINE statements in the CLASS block outside of method definitions. However, unlike procedure files where the main block is, itself executable, the CLASS or INTERFACE block in class definition files is not executable. A CLASS block does not allow any executable code to appear outside a method definition or any other separately executable block that you can define within the CLASS block. An INTERFACE block cannot contain any executable code.
Therefore, unlike the executable code that can run in the main block when you instantiate a procedure object, there is no code that can run in the main block of a class when you instantiate a class-based object, except in a constructor. To execute code during class instantiation, you must add the code to a constructor, which is a special method designed to execute for a class when it is instantiated. The main block of a procedure file can also define procedure parameters to pass when instantiating the procedure object. For a class definition file, you instead define a constructor with parameters that you pass when instantiating the class. Class files, in fact, allow you to define multiple constructors for a class definition, each of which takes a different parameter list. Thus, unlike a procedure object, which can be instantiated with only one set of procedure parameters, you can define a class that can be instantiated with different sets of parameters, depending on the constructor that you use to instantiate the class.
Finally, you cannot startup an application using a class file, as specified using the Startup Procedure (-p) startup parameter. Even if your application is otherwise built entirely using classes, you must provide a startup procedure to at least instantiate and start up the main-line class for your application.