Benefits of dynamic instances
- Last Updated: March 30, 2020
- 1 minute read
- OpenEdge
- Version 12.2
- Documentation
You can create class instances by defining a variable or property of a user-defined type and then use the new statement to create an instance of that class type. Here is an example:
using Enterprise.BusinessUnit.IBusinessUnit.
. . .
define variable D as Dept no-undo.
D = new Dept().
When you create an instance of a class this way, you must know the class name at compile time to create the class. If your application will create many class instances of various types, you will have to write a lot of type-specific code. In some cases, you may not know the types until runtime. For example, the type information is in a configuration file that is used to bootstrap the application.
In these cases, you can write your code to create and access class instances
dynamically. You use the dynamic-new statement to create an instance of
a class type and assign the instance to the variable of type Object.
Here is the syntax for creating an instance dynamically.
<object-reference> = dynamic-new <class-name>([<parms>]).
Syntax Element | Description |
object-reference | A property, variable, or field in a temp-table of type Progress.Lang.Object. |
class-name | The fully qualified class name from which the definition of the class is known at runtime. |
parms | The parameters, if any, for the public constructor for the class. |