SomRespondsTo: Difference between revisions
Appearance
Created page with "{{DISPLAYTITLE:somRespondsTo}} This method tests whether the receiving object supports a given method. Not generally overridden. Note: For backward compatibility, this method ..." |
|||
Line 48: | Line 48: | ||
* [[somSupportsMethod]] | * [[somSupportsMethod]] | ||
[[Category: | [[Category:SOMObject]] |
Latest revision as of 04:02, 13 October 2017
This method tests whether the receiving object supports a given method. Not generally overridden. Note: For backward compatibility, this method does not take an Environment parameter.
- Original Class
- SOMObject
Syntax
boolean somRespondsTo (SOMObject receiver, somId methodId)
Parameters
- receiver (SOMObject)
- A pointer to the object to be tested.
- methodId (somId)
- A somId that represents the name of the desired method.
Return Code
- rc (boolean)
- Returns TRUE if the specified method can be invoked on the receiving object, and FALSE otherwise.
Remarks
The somRespondsTo method tests whether a specific (static or dynamic) method can be invoked on the receiver object. This test is equivalent to determining whether the class of the receiver supports the specified method on its instances.
Example Code
/* ----------------------------------------- Note: Animal supports a setSound method; Animal does not support a doTrick method. ----------------------------------------- */ #include <animal.h> main() { Animal myAnimal; char *methodName1 = "setSound"; char *methodName2 = "doTrick"; myAnimal = AnimalNew(); if (_somRespondsTo(myAnimal, SOM_IdFromString(methodName1))) somPrintf("myAnimal responds to %s\n", methodName1); if (_somRespondsTo(myAnimal, SOM_IdFromString(methodName2))) somPrintf("myAnimal responds to %s\n", methodName2); _somFree(myAnimal); } /* Output from this program: myAnimal responds to setSound */