METHOD statement
- Last Updated: January 30, 2023
- 7 minute read
- OpenEdge
- Version 12.2
- Documentation
Syntax
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 ]- [ PRIVATE | PACKAGE-PRIVATE | PROTECTED | PACKAGE-PROTECTED | PUBLIC ]
- The access mode for the method. The default method access mode
is
PUBLIC.PRIVATEmethods are accessible from within the class where they are defined. An instance can access aPRIVATEmethod of another instance if they are both instances of the same class.PROTECTEDmethods are accessible from within the class where they are defined and in any subclass of the defining class. An instance can access aPROTECTEDmethod of a second instance of a class that is at the same level or in a super class in the class hierarchy. APACKAGE-PRIVATEmethod can be called from within the class and any class within its package. APACKAGE-PROTECTEDmethod can be called from within the class, any class within its package, and from within any subclass that inherits the class. You can call aPUBLICmethod from within the class that defines the method, from within any class that inherits the defining class, and from any class or procedure that references the defining class. For more information on calling methods, see Call class-based methods. - [ STATIC ]
- Specifies the scope of the method. By default, methods of a class are instance methods, meaning that a given method is defined and available for each instance of the class in which it is defined. However, methods can also be defined as static using this keyword. ABL defines a given static method on first reference to the class type in which it is defined, scopes that method to the class type, and makes it available through that class type for the duration of the ABL session. Unless specified otherwise, a reference to a method in this manual is assumed to be a reference to an instance method.
- [ ABSTRACT ]
- Declares the method as abstract using an abstract method
prototype. Each method prototype is declared by a single
METHODstatement, with a signature, but with no implementation and noEND METHODstatement. Abstract methods can be defined as eitherPROTECTEDorPUBLIC. These method prototypes cannot specify theSTATICoption. An abstract method can only be an instance method. Abstract method prototypes can be overloaded and can overload implemented method definitions. Note that a constructor or destructor cannot be abstract. - [ OVERRIDE ]
- Specifies that this method overrides a method defined in a super class in the class hierarchy. The compiler verifies that this method has the same return type, the same or a less restrictive access mode, the same scope (instance or static), and the same number, modes, and data types of parameters as a method of the same name in a super class. If any of these tests fail, the compiler generates an error.
- [ FINAL ]
- If specified, this method cannot be overridden. Any class that
inherits from this class cannot define a method with the same method name as this
method.Note: The
FINALoption is permitted but irrelevant on aPRIVATEmethod, or on any method within a class that itself has been defined asFINAL. A subclass can define a method with the same definition as aPRIVATEmethod in its super class. However in this case, the subclass has simply defined its own method and is not overriding the super class's method.
- VOID
- Indicates this method does not return a value.
- return-type
- Indicates the data type of the mthod return value. The data types
that can be returned by a method are the same data types supported for return values by
user-defined functions:
CHARACTER,CLASS,COM-HANDLE,DATE,DATETIME,DATETIME-TZ,DECIMAL,HANDLE,INT64,INTEGER,LONGCHAR,LOGICAL,MEMPTR,RAW,RECID,ROWID; whereCLASSspecifies an object reference to a class defined as either a class or interface type.Like user-defined function return types, the return-type can also include the
EXTENToption to define a one-dimensional array of a listed type. This option can specify an array return value as either determinate (has a defined number of elements) or indeterminate (has an undefined number of elements). To define a determinate array return value, specify theEXTENToption with the constant argument. This optional argument is an integer value that represents the number of elements in the array. To define an indeterminate array return value, specify theEXTENToption without the constant argumentTo set the return value for a method, you must use the
RETURNstatement with a value of the same data type as return-type. There is no implicit type conversion. - method-name
- The name of the method. The method name must be unique among all non-overloaded methods within the class and cannot be the same as the class name. This method-name must also be unique among all non-overloaded methods within the class hierarchy according to its particular class member namespace. For more information, see Namespaces for class members.
- ( [parameter[ , parameter]...] ) { : | . }
- Any parameters that you define for the method. If this method overloads another method definition of the same name, ABL must be able to disambiguate the two methods by the number, data types, or modes of their parameter definitions (their signatures). For more information on the syntax of parameter and how to define overloaded method signatures, see the Parameter definition syntax reference entry in ABL Reference.
- [ method-body END [ METHOD ] . ]
- The logic of an implemented method, which can be composed of any ABL
statements currently allowed within an internal procedure, plus the syntax that is
restricted to classes and their methods. An implemented method must include a method-body, followed by an
ENDstatement, even if it contains no statements (is empty). An abstract or interface method prototype cannot specify a method-body at all.
Adding a method to the acme.myObjs.CustObj sample class definition results in this code:
|
Adding an abstract method to the super class, acme.myObjs.Common.CommonObj, results in this code:
|
Implementing the abstract MessageHandler( ) method in the CustObj class
results in this code:
|