The class_of/2
predicate is used to test whether an object is of a
particular type or to determine the type of an object. Similarly, the
descendant_of/2
predicate relates an object to all ancestors of its
class. (Remember that the object's class is, itself, an ancestor class
of the object.)
Both require the first argument (the object) to be instantiated. That is, the predicates cannot be used to find objects of a given class. If you need to search among all the objects of a class, you must provide a way to do it. One way to do this is to assert a fact connecting the class name to every object, when it is created. The named_point example of the previous section took that idea a step further by allowing each object to have a different name.
The pointer_object/2
predicate relates an object's address (a pointer)
to the object. Remember that an instance of Class is represented by a
term of the form
Class(Address)
The pointer_object/2
predicate requires that one of its arguments be
instantiated, but it may be either one. Hence, just by knowing the
address of an object (which possibly was returned by a foreign
function) it is possible to determine the object's type.
Most Prolog programmers can safely ignore the pointer_object/2
predicate, unless they are using Quintus Objects with foreign
functions or with the Structs package.