Try OpenEdge Now
skip to main content
Object-oriented Programming
Getting Started with Classes, Interfaces, and Objects : Defining classes : Defining behavior in a class : Methods of a class
 
Methods of a class
Methods encapsulate executable code for a class, much like internal procedures or user-defined functions for a procedure-based object. Like data members and properties, methods have an access mode, which defines where and how you can call the method. As for data members and properties, the access mode of a method determines the context within an application where the method is visible and available for execution. You can call private methods from within the class in which they are defined. An instance can access a private method of another instance as long as they both belong to the same class. You can call protected methods from within the class hierarchy where they are defined and in any subclass of the defining class. An instance can call 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. You can call public methods both from within the class hierarchy and from outside the class hierarchy where they are defined.
Classes support four types of methods:
*Named methods, which you can define as needed and which you invoke by name, similar to procedures or user-defined functions. A method must also specify a return type, but that return type can be VOID, which means that no value is returned by the method. Methods can have zero or more parameters.
*Accessors, which are specified for a property when you define it and which are invoked when you read or write the property.
*Constructors, which you can define as needed and which can be invoked when you instantiate the class. You can provide one or more constructors (overloaded with different parameter lists) when the class needs to initialize data for an object during class instantiation. Providing overloaded constructors allows you to instantiate the same class with different initial data. If you do not provide a constructor, ABL provides a default constructor in order to instantiate the class. The default constructor has no parameters, and if you provide a constructor with no parameters, ABL treats this constructor as the default constructor.
*A destructor, which you can define as needed and which is automatically invoked during garbage collection or when you delete the class instance explicitly. You can provide a destructor when the class needs to free resources or do other cleanup work when a class instance is destroyed. If a destructor is not provided, ABL provides a default destructor in order to delete the object.
Note: Classes also support built-in methods on events of a class (event methods). You can manage class events by invoking these methods on them.