Navigation  without Java Scripts

Static Class Members

Class member predicates and facts can be declared being static. Notice that all domains declared in classes are static class entities.

The keyword static specified before the keyword PREDICATES or FACTS specifies that all predicates or facts declared in the section are static. For example:

STATIC PREDICATES
procedure get_counter(integer)
STATIC FACTS
determ counter(integer)
Static class members belong to the class, not to the individual objects. This means that when a class declares a static member, then only one such member exists for a class, rather than one per each object (like it is for object class members). Static class members do not have any reference to personal objects of the class. Therefore, static class members (public) can be used outside the class in which they are declared without references to objects of this class. They can be used in any place where the class is visible (in modules including the class declaration) even without creation of objects of the class.

In classes that do not inherit (transitively) the static class member, it can be qualified using the following syntax:

class_name :: static_class_member_name[(arguments)]
For example, one can access static fact counter like this:
goal
...
xclass::counter(Current_Counter)
...
In opposite, non-static (object) class members belong to the class objects (instances). Therefore, to use an object class member outside the class implementation an object of the class should be created, and the object identifier should be specified in the call of object class member.

Static facts are not generated for each instance of a class. Only one version of each static fact exists for the class and it is accessible for all instances of the class. This is useful, for example, to count the number of instances of a class.

Static predicate values do not carry any internal reference to class instances. Therefore, "ordinary" predicate domains can be used for declarations of static predicate values (see Example).

On the other hand, object predicate values carry the hidden extra parameter pointing to the actual instance (object) of the class. Therefore, object predicate values can be declared only inside a class, and to declare non-static predicate values the special object predicate domains should be used.

Note that it is impossible to declare static predicates in abstract classes.

See also