SourceForge.net Logo

How to create an instance?

According to JMI class proxy objects are used to create instance objects. For every modeled class in UML such a class proxy object is generated by the JMI mapping. E.g. for the UML class Person the class proxy object PersonClass is generated. These class proxy objects provide factory operations that allow the clients to create instance objects.

In order to create an instance, the corresponding class proxy object must be retrieved. For this purpose the package object that contains the desired class proxy object must retrieved first. For more information about how to retrieve the package objects, please refer to How to retrieve a package?. For every class proxy object within the package a get operation is provided to access the class proxy. This class proxy object can then be used to create instance objects.

The following example illustrates how to retrieve a class proxy object and how to create an instance by means of the class proxy object.

Example 4-2. Create a new instance of class Person

// retrieve class proxy for class Person from package
PersonClass personClass = lab1Pkg.getPersonClass();

// use class proxy to create a new Person instance
Person person = personClass.createPerson();