Define methods
- Last Updated: September 13, 2022
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
Within the main block of a class, you can specify executable behavior by defining methods as class members.
This is the syntax for defining a class-based method using the METHOD statement:
|
Element descriptions for this syntax diagram follow:
- method-modifiers
- A list of options that modify the behavior of the method. They can
appear in any order as specified in the following syntax:
[ PRIVATE | PACKAGE-PRIVATE | PROTECTED | PACKAGE-PROTECTED |PUBLIC ][ STATIC | ABSTRACT ] [ OVERRIDE ][ FINAL ]
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 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. PACKAGE-PRIVATE— A package-private method can be called from within the class and any class within its package.-
PROTECTED— A protected method can only be invoked from within the class hierarchy. -
PACKAGE-PROTECTED— A package-protected method can be called from within the class, any class within its package, and from within any subclass that inherits the class. -
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 Use static members of a class.
For information on the ABL to call methods, see Call class-based methods. For more information on defining methods, see Define methods within a class.