1-148 SOMobjects Base Toolkit: Programmer’s Reference Manual
somIsA Method
Purpose
Tests whether an object is an instance of a given class or of one of its subclasses. Not
generally overridden.
IDL Syntax
boolean somIsA (in SOMClass aClass);
Note: For backward compatibility, this method does not take an Environment parameter.
Description
Use the somIsA method to determine if an object can be treated like an instance of aClass.
SOM guarantees that if somIsA returns true, then the receiver will respond to all (static or
dynamic) methods supported by aClass.
Parameters
receiver A pointer to the object to be tested.
aClass A pointer to the class that the object should be tested against.
Return Value
The somIsA methods returns 1 (true) if the receiving object is an instance of the specified
class or (unlike somIsInstanceOf) of any of its descendant classes, and 0 (false) otherwise.
C Example
#include <dog.h>
/* --------------------------------
: Dog is derived from Animal.
-------------------------------- */
main()
{
Animal myAnimal;
Dog myDog;
SOMClass animalClass;
SOMClass dogClass;
myAnimal = AnimalNew();
myDog = DogNew();
animalClass = _somGetClass (myAnimal);
dogClass = _somGetClass (myDog);
if (_somIsA (myDog, animalClass))
somPrintf (”myDog IS an Animal\n”);
else
somPrintf (”myDog IS NOT an Animal\n”);
if (_somIsA (myAnimal, dogClass))
somPrintf (”myAnimal IS a Dog\n”);
else
somPrintf (”myAnimal IS NOT a Dog\n”);
_somFree (myAnimal);
_somFree (myDog);
}
/*
Output from this program:
myDog IS an Animal
myAnimal IS NOT a Dog
*/
Commenti su questo manuale