somCastObj
This method changes the behavior of an object to that defined by any ancestor of the true class of the object.
- Original Class
- SOMObject
Syntax
boolean somCastObj (SOMObject receiver, SOMClass ancestor)
Parameters
- receiver (SOMObject)
- A pointer to an object of type SOMObject.
- ancestor (SOMClass)
- A pointer to a class that is an ancestor of the actual class of the receiver.
Return Code
- rc (boolean)
- TRUE Returns 1 (TRUE) if the operation is successful.
- FALSE Returns 0 (false) if the operation is not successful. The operation fails if ancestor is not actually an ancestor of the class of the object.
Remarks
This method changes the behavior of an object so that its behavior will be that of an instance of the indicated ancestor class (with respect to any method supported by the ancestor). The behavior of the object on methods not supported by the ancestor remains unchanged.
This operation actually changes the class of the object (since an object's behavior is defined by its class). The name of the new class is derived from the initial name of the object's class and the name of the ancestor class, as illustrated in the Example.
This method may be used on an object multiple times, always with the restriction that the ancestor class whose behavior is selected is actually an ancestor of the true (original) class of the object.
Example Code
#include <som.h> main() { SOMClassMgr cm = somEnvironmentNew(); SOM_Test(1 == _somCastObj(cm, _SOMObject)); _somDumpSelf(cm, 0)); SOM_Test(1 == _somResetObj(cm)); _somDumpSelf(cm, 0); } /* output: * {An instance of class SOMClassMgr->SOMObject * at address 20061268 * } * {An instance of class SOMClassMgr at address 20061268 * ... <SOMClassMgr State Information> ... * } */