There are several ways that client programs can take advantage of the somDefaultInit object initialization. If desired, clients can use the SOM API directly (rather than taking advantage of the usage bindings). Also, the general object constructor, somNew, can always be invoked on a class to create and initialize objects. This call creates a new object and then invokes somDefaultInit on it
To use the SOM API directly, the client code should first invoke the somNewNoInit method on the desired class object to create a new, uninitialized object. Then, the desired initializer is invoked on the new object, passing a null (that is, 0) control argument in addition to whatever other arguments may be required by the initializer. For example:
/* first make sure the Example2 class object exists */ Example2NewClass(Example2_MajorVersion, Example2_MinorVersion); /* then create a new, uninitialized Example2 object */ myObject = _somNewNoInit(_Example2); (null) /* then initialize it with the desired initializer */ Example2_withName(myObject, env, 0, "MyName");
Usage bindings hide the details associated with initializer use in various ways and make calls more convenient for the client. For example, the C usage bindings for any given class already provide a convenience macro, <className>New, that first assures existence of the class object, and then calls somNew on it to create and initialize a new object. As explained above, somNew will use somDefaultInit to initialize the new object.
Also, the C usage bindings provide object-construction macros that use somNewNoInit and then invoke non-default initializers. These macros are named using the form <className>New_<initializerName>. For example, the C usage bindings for "Example2" allow using the following expression to create, initialize, and return a new "Example2" object:
Example2New_Example2_withName(env, "AnyName");In the C++ bindings, initializers are represented as overloaded C++ constructors. As a result, there is no need to specify the name of the initializer method. For example, using the C++ bindings, the following expressions could be used to create a new "Example2" object:
new Example2; // will use somDefaultInit new Example2(); // will use somDefaultInit new Example2(env,"A.B.Normal"); // will use Example2_withName new Example2(env,123); // will use Example2_withSize
Observe that if multiple initializers in a class have exactly the same signatures, the C++ usage bindings would be unable to differentiate among the calls, if made using the forms illustrated above. In this case, a client could use somNewNoInit first, and then invoke the specific initializer, as described in the preceding paragraphs.