Defines a constructor for a class. A constructor is a special type of method that ABL invokes to initialize data for a new object of a class that is instantiated using the NEW function (classes), NEW statement, or DYNAMIC-NEW statement, or to initialize static members of a class.
Note:
CONSTRUCTOR PRIVATE PROTECTED PUBLIC STATIC class-name( parameter , parameter ) :constructor-bodyPRIVATE PROTECTED PUBLIC STATICPRIVATE specifies an instance constructor that you can call explicitly within another constructor of the defining class (using the THIS-OBJECT statement) during class instantiation, or that a static method or static constructor of the class can invoke by executing the NEW function (classes) in order to allow the class to instantiate itself. An instance can directly call a private constructor of its own class.PROTECTED specifies an instance constructor that you can call explicitly within a constructor of an immediately inheriting subclass (using the SUPER statement) during class instantiation. An instance can call a protected constructor as long as the constructor is defined in the same class as the instance or a superclass of the instance.The name of the class this method constructs. This name must match the class name portion of the type name for the class (that is, the name of the class definition file excluding the .cls extension and any package path information).If this instance constructor is one of several overloaded constructors defined for a class, the parameter list must be unique among all the other constructors. This uniqueness can be established using a different combination of number, data types, or modes for the parameters. For information on the parameter definition syntax and establishing uniqueness for overloaded constructors, see the Parameter definition syntax reference entry. Note that any defined static constructor does not participate in constructor overloading with instance constructors.
constructor-logic
. . .END CONSTRUCTOR .When you invoke an instance constructor that takes parameters, again, you must invoke that constructor as the first executable statement in the invoking constructor. If you want to invoke a super class instance constructor, you must invoke the SUPER statement with parameters that match the parameters of the super class constructor with respect to number, data type, and mode.If you want to invoke an overloaded instance constructor of the defining class, you must invoke the THIS-OBJECT statement as the first statement, with parameters that match the parameters of the overloaded constructor with respect to number, data type, and mode. If you invoke an overloaded constructor, and that overloaded constructor does not invoke another overloaded constructor, it must invoke a super class constructor, either implicitly (the default) or explicitly as its first statement. So, in any chain of explicit calls from one overloaded constructor to another, the last overloaded constructor in the chain must invoke a super class constructor.END CONSTRUCTORFor more examples of constructor definitions, including a static constructor and a constructor for an abstract class, see the descriptions of r-CustObj.cls, r-CustObjStatic.cls, and r-CustObjAbstract.cls in the CLASS statement reference entry.
You never explicitly invoke an instance constructor to create a class instance. The constructor is implicitly invoked when you instantiate the defining class using the NEW function (classes), NEW statement, or DYNAMIC-NEW statement, passing any parameters required to identify the instantiating constructor. The instantiating constructor then directly or indirectly calls an instance constructor in its immediate super class, which similarly calls an instance constructor in its immediate super class, and so on for all classes in the class hierarchy, until the default instance constructor of the root (Progress.Lang.Object class) is called. From this point, the root constructor and all previously called instance constructors complete execution in reverse order of invocation, terminating class instantiation with completion of the initial instantiating constructor.
Within a class hierarchy, you can explicitly invoke an instance constructor from an instance constructor of an immediate subclass using the SUPER statement or from an overloaded constructor in the same defining class using the THIS-OBJECT statement. The invoking constructor must specify any parameters required to identify the called constructor. These parameters must match the constructor parameters with respect to the number, data type, and mode.
You can handle application errors in an instance constructor as in any ABL block. However, by executing a RETURN ERROR action at the block level or a THROW action at the block level with the presence of a BLOCK-LEVEL ON ERROR UNDO, THROW statement, or a ROUTINE-LEVEL ON ERROR UNDO, THROW statement, the AVM returns the ERROR condition from the constructor block. With this returned ERROR condition, ABL terminates creation of the object. If any part of the class hierarchy has been created (constructors executed), ABL executes the corresponding destructors for those classes automatically and raises ERROR on the statement that instantiated the class. If this constructor is invoked as part of a NEW statement or DYNAMIC-NEW statement, the data element set to receive an object reference to the failed class instantiation remains unchanged. If a RETURN ERROR also includes the option to return a character string value, or you set the ReturnValue property of a Progess.Lang.AppError object that you THROW, you can get this value using the RETURN-VALUE function following the statement that attempted to instantiate the class or in a CATCH block that catches the Progress.Lang.AppError object. For more information, see OpenEdge Development: Object-oriented Programming.
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates. |