Try OpenEdge Now
skip to main content
Object-oriented Programming
Object-oriented Programming and ABL : Overview of class-based ABL : Defining methods
 

Defining methods

Within the main block of a class, you can specify executable behavior by defining methods as class members. ABL allows you to define a named method (here on referred to simply as a method) as a block that always begins with the METHOD statement and always ends with the END METHOD statement. A method can be defined with an access mode of PRIVATE, PROTECTED, or PUBLIC, where PUBLIC is the default. Where and how a method can be invoked depends on its access mode:
*PRIVATE — A private method can be invoked only from within the defining class itself, although an instance can access a private method of another instance if both instances are from the same class.
*PROTECTED — A protected method can only be invoked from within the class hierarchy. An instance of a class can invoke a protected method of a second instance of a class that is at the same level or in a super class in the class hierarchy.
*PUBLIC — A public method can be invoked from inside or outside the class hierarchy.
A method can have parameters and a defined return type (similar to a user-defined function), which together represent its signature; its return type can also be VOID, which means that it does not return a value. You can also define a method as FINAL, which means that it cannot be overridden in a subclass. The statements that you include inside a method block can include most of the statements that you include within the block of an internal procedure or user-defined function. You can override any inherited method not defined as FINAL by implementing it with an identical signature and a different method block.
A method override can also specify a less restrictive access mode. It is the method override in the most derived class that provides the method behavior to the entire class hierarchy and its consumers.
Each non-overridden method defined within a class must have a unique identity, but multiple methods in the class can have the same name as long as they are overloaded with unique calling signatures.
Within an abstract class, you can also define a method as ABSTRACT (and not FINAL), which means that it must be overridden and implemented in a subclass. An abstract method is defined only by its signature, as a prototype, without any code block or associated END METHOD statement. The first non-abstract derived class in the subclass hierarchy must override and implement the method as non-abstract (with a code block and terminating END METHOD statement), unless an abstract class has already done so. As with any method override, the non-abstract override of the method in the most derived class provides the method implementation used by the class hierarchy and its consumers, and any method override (abstract or non-abstract) can specify a less restrictive access mode.
ABL also supports static methods that are associated with a class type rather than a class instance as for instance methods. Unless otherwise specified, any reference to a method in this manual refers to an instance method. For more information on static class members, see Usingstatic members of a class.
For information on the ABL to call methods, see Callingclass-based methods. For more information on defining methods, see Definingmethods within a class.
* Comparison with procedure-based programming