Difference between revisions of "Language Reference/Classes"

From wiki.visual-prolog.com
m (links)
m
 
Line 49: Line 49:
*{{lang2|Predicates|Predicates_Sections|predicatesSection}}
*{{lang2|Predicates|Predicates_Sections|predicatesSection}}
*{{lang2|Predicates|Constructors_Sections|constructorsSection}}
*{{lang2|Predicates|Constructors_Sections|constructorsSection}}
*{{lang2|Properties|Properties_Sections|PropertiesSection}}
*{{lang2|Properties|Properties_Sections|propertiesSection}}
*{{lang2|Directives|Conditional_Compilation|conditionalSection}}
*{{lang2|Directives|Conditional_Compilation|conditionalSection}}



Latest revision as of 10:18, 10 July 2017

A class declaration defines the appearance of the class to the surroundings: the surroundings can see and use exactly those entities mentioned in the class declaration. We say that the declaration of a class specifies the public part of the class.

A class declaration can contain constant and domain definitions and predicate declarations.

If the class states a construction type ConstructionType, then it constructs objects of that type. Object constructing classes have at least one constructor, but more can be declared. Classes that do not explicitly declare any constructors are automatically equipped with the default constructors (i.e. new/0).

Objects are constructed by invoking one of constructors of the class.

Constructors are also used when initializing inherited classes.

Everything mentioned in a class declaration belongs to the class, rather than to objects it constructs. Everything that relates to the objects must be declared in the construction type of the objects constructed by the class.

Any class declaration ClassDeclaration must have an accompanying class implementation ClassImplementation. The definition/implementation of predicates declared in the class declaration is provided by the class implementation. Likewise the definition of the predicates supported by the objects constructed by the class is provided by the class implementation. Both kinds of predicates can be implemented by clauses, but object predicates can also be inherited from other classes.

It is important to notice that a class declaration does not state anything about code inheritance. Code inheritance is a completely private matter that can only be stated in the class implementation. (This is unlike many other object oriented programming languages, and serves to hide all implementation details in the implementation).

If the class does not state a construction type ConstructionType, then the class cannot manufacture any objects; it therefore plays the role of a module rather than a "real" class.

ClassDeclaration :
    class ClassName ConstructionType-opt
        ScopeQualifications
    Sections
    end class ClassName-opt
ConstructionType :
    : InterfaceName
ClassName :
    LowerCaseIdentifier

See also Generic Interfaces and Classes and Monitors.

The ClassName in the end of the class declaration must (if present) be identical to the one in the beginning of the class declaration.

Notice that you can use the same class name ClassName as the interface name ConstructionType specified as the construction type to this class. That is you can write:

class interfaceAndClassName : interfaceAndClassName

Notice that both the class and the interface can declare domains and constants and these must not conflict with each other since they end up in the same name space (because they can be qualified only with the same name of the interface or the class).

The ScopeQualifications must be of the kind OpenQualification.

The Sections must be of the kinds:

constructorsSections are only legal if the class states a ConstructionType.

All sections contained (transitively) in conditional sections must also be of those kinds.