Navigation  without Java Scripts

DOMAINS Section in the Class Declaration

The domains sections in the class declaration declare domains - members of the class. The default access rights of domains declared in the class declaration are public.

Syntax

[PROTECTED] DOMAINS <domains_declarations>
where:
DOMAINS declares the domains section
PROTECTED changes the access rights of domains declared in the section from public (default) to protected. A protected domain can be used only inside the class in which it is declared and in the classes that directly inherit from this class.
<domains_declarations> a list of declarations of domains.

Remarks

Possibility to declare domains in classes is supported beginning with Visual Prolog v.5.2. It is possible to declare domains both in the class declaration and in the implementation.

Public domains declared in a class declaration are global domains and can be used outside the class. Notice that public domains declared in non-abstract classes do not even have to be visible in the main module (if they are not really used in the main module) like "ordinary" global domains have to.

A public domain declared in a class declaration can be used directly in all classes that inherit (transitively) from that class (including the class itself). The domain can be used both in the declarations and in the implementations of these classes.

A protected domain declared in a class declaration can be used directly in this class and in all classes directly inherit from that class (i.e. explicitly specify this class in the base class list). The domain can be used both in the declarations and in the implementations of these classes.

From the other hand, domains declared in a class implementation are private and can be used only inside that implementation. In other words, domains declared in a class implementation are local to that implementation.

In classes that do not inherit (transitively) from the class class_name declaring the public domain, the domain and functors of the domain alternatives have to be qualified with the class name of the declaring class.

[class_name]::<domain_name>
The qualification have to go to the class that really declares the domain, it cannot go to a class that merely inherit from that class. In other words, the derived classes only "inherit" the ability to use a domain.

Notice that all domains declared in classes are static/class entities. That is the domain belongs to the class not to the individual objects. Thus if a class declares a domain this means that there will exist one domain, rather than one per object.

Being able to declare domains in classes opens the possibility to use classes as modules.

Example

class xclass
domains
myDom =string % public domain
obj_dom = object procedure (myDom) - (i) % object predicate domain
predicates
pv : obj_dom
endclass
implement xclass
clauses
pv(S):- write(S),nl.
endclass
goal
O = xclass::new,
O:pv("Hello world!"),
PredValue = O:pv,
O:PredValue("I am object predicate value!"),
O:delete.
See also