Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming

> ## Creating a class instance using the NEW statement

> The `NEW` statement is used to create an instance of a class. At run time, the `NEW` statement locates the named class on the `PROPATH` using the package information in the class type name and invokes the constructor to create a new instance of the class. The instantiated class is also referred to as a class-based object. The `NEW` statement assigns a reference for the new class instance to an object reference variable.

> This is the syntax for instantiating a class using the `NEW` statement:

> Syntax
>     object-reference = NEW type-name ( [ parameter [ , parameter ] ... ] )
>         [ NO-ERROR ] .

> Element descriptions for this syntax diagram follow:

> ``object-reference``

> The name of a variable, parameter, or temp-table field appropriately defined as a class type. The class type name used in the `object-reference` definition must follow the rules for `type-name`.

> Note: If `object-reference` is a temp-table field, its class type name can only be `Progress.Lang.Object`, the Progress root class. For more information on the Progress root class, see the "Using the root class — Progress.Lang.Object" section.

> ``type-name``

> The type name of the class to instantiate. For more information type names, see the "Using the CLASS construct" section

> This type name must also match the type name for one of the following classes involved in the class hierarchy of the class type name used to define `object-reference`:

> - The class specified in the definition of `object-reference`.
> - A class that is a subclass of the class specified in the definition of `object-reference`.
> - A class that implements the interface specified in the definition of `object-reference`.
> `[ `parameter` [ , `parameter` ] ... ]`

> The parameters of the constructor. For more information on the syntax of `parameter`, see the “Parameter passing syntax” reference entry in OpenEdge Development: Progress 4GL Reference .

> Whenever an instance of a class is created, the constructor of the instantiated class, as well as the constructors of any super classes in its class hierarchy are run. The instantiated object gets its own copy of the `PROTECTED` and `PUBLIC` data members defined in the class hierarchy. Thus, just as with persistent procedures, each instance of a class is a separate entity with its own instance data.

> This example, from the `Main` class described previously (see the "Defining an object reference as a variable" section), creates instances of two sample classes in its constructor:

>     CLASS Main:
>         DEFINE PRIVATE VARIABLE rCustObj
>             AS CLASS acme.myObjs.CustObj NO-UNDO.
>         ...
>         DEFINE PRIVATE VARIABLE rHelperClass
>             AS CLASS acme.myObjs.Common.HelperClass NO-UNDO.
>         CONSTRUCTOR PUBLIC Main( ):
>             /* Create an instance of the HelperClass class */
>             rHelperClass = NEW acme.myObjs.Common.HelperClass( ).
>             /* Create an instance of the CustObj class */
>             rCustObj = NEW acme.myObjs.CustObj( ).
>         END CONSTRUCTOR.
>         ...
>     END CLASS.

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