Next: Exception Handling
Up: Writing Methods
Previous: Class and Instance Methods
Adding and removing methods are basic operations in an object-oriented
environment. They are defined on class Root, therefore they
can be invoked on every class via inheritance.
To add a new method to the system call
- (METHOD * ) GRAPE(class, "add-method")(name, func)
- CLASS * class
char * name
void *(* func)()
This will add a new method to the method list of class class. The
method is called name, func is the pointer to the function
which implements the new method. The return value of "add-method" is
the pointer to the structure of the new method, it should only be used to
check if the method was successfully added. If the method couldn't be
added (maybe there was already a method called name), an error
message will be printed and "add-method" returns NULL.
By calling
- GRAPE(class, "delete-method")(name)
- CLASS * class
char * name
the method name can be removed from the method list of class
class, and with
- (METHOD * ) GRAPE(class/inst, "find-method")(name)
- CLASS * class
INSTANCE * inst
char * name
it can be tested if a method named name exists on class class
resp. on the class of the instance inst (of course the superclasses
are also searched if necessary). The methods return a NULL pointer
if the method wasn't found.
SFB 256 Universität Bonn and IAM Universität Freiburg Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik,
Universität Bonn.