4-8 SOMobjects Base Toolkit Programmer’s Reference
Manual
sommGetSingleInstance Method
Purpose
Gets the one instance of a specified class for which only a single instance can exist.
IDL Syntax
SOMObject sommGetSingleInstance ( );
Description
The sommGetSingleInstance method gets a pointer to the one instance of a class for
which only a single instance can exist. A class can have only a single instance when its
metaclass is the SOMMSingleInstance metaclass (or is a subclass of it).
The first call to <className>New in C, the new operator in C++, or the somNew method
creates the one possible instance of the class. Thereafter, any subsequent “new” calls
return the first (and only) instance. Using the sommGetSingleInstance method offers an
advantage, however, in that the call site explicitly shows that something special is occurring
and that a new object is not necessarily being created. (That is, the
sommGetSingleInstance method creates the single instance if it does not already exist.)
Parameters
receiver A pointer to a class object whose metaclass is SOMMSingleInstance (or is
a subclass of it).
ev A pointer where the method can return exception information if an error is
encountered.
Return Value
The sommGetSingleInstance method returns a pointer to the single instance of the
specified class.
Example
Suppose the class “XXX” is an instance of SOMMSingleInstance; then the following C
code fragment passes the assertions.
x1 = XXXNew();
x2 = XXXNew();
assert( x1 == x2 );
x3 = _sommGetSingleInstance( _somGetClass( x1 ), env );
assert( x2 == x3 );
Note that the method sommGetSingleInstance is invoked on the class object, because
sommGetSingleInstance is a method introduced by the metaclass SOMMSingleInstance.
Original Class
SOMMSingleInstance
Kommentare zu diesen Handbüchern