Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## CONSTRUCTOR statement

> Defines a constructor method for a class. Progress invokes this constructor method to initialize data or state for a new class object instance when the object is instantiated using the NEW statement.

> Note: This statement is applicable only when used in a class definition (`.cls`) file.

> #### Syntax

>     CONSTRUCTOR { PROTECTED | PUBLIC } class-name
>       ( [ parameter [, parameter ] ... ] ):
>       constructor-body

> `{ PROTECTED | PUBLIC }`

> Specifies the access mode for this constructor method.

> A class with a PROTECTED constructor method can be accessed only by an inheriting class.

> A class with a PUBLIC constructor method can be accessed by the defining class, any of its inheriting classes, and any class or procedure that instantiates the class using the NEW statement.

> ``class-name``

> 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).

> `( `parameter` [, `parameter` ] ... )`

> Optionally specifies one or more parameters of the constructor method.

> For the parameter definition syntax, see the Parameter definition syntax reference entry in this book.

> The NEW statement, which creates an object instance of the class, must provide for the parameters identified by this constructor method. The parameters must match with respect to the number, data type, and mode. For more information about the NEW statement, see the NEW statement reference entry in this book.

> ``constructor-body``

> The body of the constructor definition. Define the constructor body using the following syntax:

>            .
>            .
>            .
>     method-logic
>            .
>            .
>            .
>     END [ CONSTRUCTOR ].

> ``method-logic``

> The logic of the constructor method, which can contain any Progress 4GL statements currently allowed within a PROCEDURE block including class-related statements, but excluding the RETURN ERROR statement. This typically contains logic to initialize the data members in the class.

> If the defining class of this constructor method is a subclass and its super class contains a constructor method that takes parameters, the first executable statement in this constructor method must invoke the constructor method for the super class using the SUPER( ) method and the parameters must match with respect to the number, data type, and mode. For more information, see the SUPER( ) method reference entry in this book.

> If the constructor method for the super class does not take parameters, you need not invoke it. Progress automatically invokes the constructor method for the super class when it instantiates the class object.

> `END [ CONSTRUCTOR ]`

> Specifies the end of the constructor body definition. You must end the constructor body definition with the END statement.

> Example

> The following example shows the definition of a constructor method:

>     CONSTRUCTOR PUBLIC CustObj( ):
>       m_NumCusts = 0.
>       /* Fill a temp table and get the row count */
>       FOR EACH Customer NO-LOCK:
>         CREATE ttCust.
>         ASSIGN
>           ttCust.CustNum = Customer.CustNum
>           ttCust.Name = Customer.Name
>           m_NumCusts = m_NumCusts + 1.
>       END.
>     END CONSTRUCTOR.

> #### Notes

> - You can terminate a CONSTRUCTOR statement with either a period (.) or a colon (:).

> - A constructor method definition must begin with the CONSTRUCTOR statement and end with the END statement.

> - A constructor method has no return type.

> - You never explicitly invoke the constructor method to create a class object instance. The method is implicitly invoked when the object is instantiated with the NEW statement, or explicitly invoked by the constructor method in an inheriting subclass using the SUPER( ) method.

> - Any application logic errors that occur within the constructor method must be programmatically propagated back to the calling procedure. Consider using an output parameter to return the error condition to the calling procedure, or deleting the object from within the constructor. For more information, see OpenEdge Getting Started: Object-oriented Programming .

> #### See also

> CLASS statement, DESTRUCTOR statement, FUNCTION statement, NEW statement, SUPER( ) method

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095