THIS-OBJECT statement
- Last Updated: October 30, 2020
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
THIS-OBJECT statement
Syntax
A
super class constructor can only be called (explicitly or implicitly)
once from the instantiating subclass constructor as its very first action.
If all immediate super class constructors are defined with parameters (there
is no default constructor), it is invalid for the instantiating
constructor not to call a super class constructor, either explicitly,
using the SUPER statement, or implicitly through
an explicit call to an overloaded constructor using the THIS-OBJECT statement
whose first action is ultimately an explicit call to a super class
constructor using the SUPER statement. If the super
class has a default constructor, there is no need for a subclass
to use the SUPER statement to explicitly invoke
a super class constructor, unless the application requires it.
This
is the syntax to invoke an overloaded constructor (defined in the instantiated
class) using the THIS-OBJECT statement:
|
Element description for this syntax diagram follow:
- [ parameter [ , parameter]...]
- The parameters, if any, passed to the specified constructor. For more information on the syntax of parameter, see the Parameter passing syntax reference entry in ABL Reference.
NO-ERROR on the THIS-OBJECT statement.
Any ERROR condition raised during execution of
a constructor can be handled only by the statement that instantiates
a class with the NEW function. For more information,
see Raise and handle error conditions.If
all immediate super class constructors are defined with parameters
(there is no default super class constructor), the first statement
of a constructor must either be the SUPER statement
to invoke a super class constructor, or the THIS-OBJECT statement
to call another constructor overloading with the current class.
Refer, again, to this sample class hierarchy:
|
A class or procedure that uses the NEW function
to instantiate acme.myObjs.NECustObj invokes the NECustObj( ) constructor.
This constructor must first execute its super class constructor.
As previously noted, this can be either an explicit call—with the SUPER statement
as the first executable statement—or an implicit call to the CustObj( ) constructor.
The acme.myObjs.CustObj class, in turn, does the
same for its super class constructor in acme.myObjs.Common.CommonObj.
Because acme.myObjs.Common.CommonObj is the top
of the user-defined class hierarchy, it is the first user-defined
constructor to execute to completion.
But before the constructor
for acme.myObjs.Common.CommonObj runs, the constructor
for the built-in root class, Progress.Lang.Object,
is executed, which executes standard startup behavior required by
the AVM to instantiate classes at run time. The constructor for
the top-level user-defined class does not ever need to explicitly
invoke the constructor for Progress.Lang.Object (which
relies on the default). Once the top-level user-defined constructor
in acme.myObjs.Common.CommonObj completes, the CustObj( ) constructor
is executed to completion followed by the NECustObj( ) constructor.
NEW function to
instantiate an additional acme.myObjs.NECustObj object,
the r-code for all classes in the new object’s class hierarchy is
shared with the previously instantiated object, but the constructors
for all classes execute again for the new object instance (possibly,
with different data).The following example adds a constructor
to the sample subclass, acme.myObjs.NECustObj,
described in Override methods within a class hierarchy. This constructor adds code to initialize the
class temp-table, ttEmail, as shown:
|
Constructors can have an access mode of PUBLIC, PACKAGE-PROTECTED, PROTECTED, or PACKAGE-PRIVATE.
The following example demonstrates the use of a PROTECTED
constructor. The super class SuperOnly cannot be
instantiated directly from outside the class hierarchy, because it does not have a PUBLIC constructor.
Class SuperOnly can
only be instantiated by instantiating a class that inherits from
it, such as MyPubClass:
|
|