1-146 SOMobjects Base Toolkit: Programmer’s Reference Manual
somInit Method
Purpose
Initializes instance variables or attributes in a newly created object. Designed to be
overridden.
Note: The newer somDefaultInit method is suggested instead.
IDL Syntax
void somInit ( );
Note: For backward compatibility, this method does not take an Environment parameter.
Description
The somInit method is invoked to cause a newly created object to initialize its instance
variables or attributes.
Note: The newer somDefaultInit method performs object initialization more efficiently and
is now the preferred approach for overriding initialization in an implementation file.
(The somInit method still executes correctly as before.)
Because instances of SOMObject do not have any instance data, the default
implementation does nothing. It is provided as a convenience to class implementors so that
initialization of objects can be done in a uniform way across all classes (by overriding
somInit). This method is called automatically by somNew during object creation.
A companion method, somUninit, is called whenever an object is freed. These two
methods should be designed to work together, with somInit priming an object for its first
use, and somUninit preparing the object for subsequent release.
If objects of your class contain instance variables or attributes, override the somInit method
to initialize the instance variables or attributes when instances of the class are created.
When overriding this method, always call all parent (base) classes’ versions of this method
before doing your own initialization, as follows:
1. The overriding implementation should invoke the parent method for each parent. For
users of the C or C++ implementation bindings, this can be done in either of two ways:
a. By calling a <className>_parents_<methodName> macro (which automatically
invokes all parent methods) or
b. By calling the <className>_parent_<parentName>_<methodName> macro on each
parent separately.
For more information on parent method calls, see the topic “Extending the
Implementation Template” in Chapter 5, “Implementing Classes in SOM,” of the SOM
Toolkit User’s Guide.
2. The code must be written so that it can be executed multiple times without harm on the
same object. This is necessary because, under multiple inheritance, parent method calls
that progress up the inheritance hierarchy may encounter the same ancestor class more
than once (where different inheritance paths “join” when followed backward). A check
can be made to determine whether a particular invocation of somInit is the first on a
given object by examining the contents of its instance variables; all the instance
variables of a newly created SOM object are set to zero before somInit is invoked on
that object.
Komentarze do niniejszej Instrukcji