Difference between revisions of "Language Reference/Basic Concepts/Object System"
m (Categorized) |
(review) |
||
(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==== External View ==== | ==== External View ==== | ||
This section clarifies the class-related notions in Visual Prolog at a conceptual level. It does not discuss syntax or implementation details. | |||
The class concept | The class concept in Visual Prolog is based on three semantic entities: | ||
*objects | * objects | ||
*interfaces | * interfaces | ||
*classes | * classes | ||
===== Object ===== | ===== Object ===== | ||
An ''object'' is set of named ''object member predicates'' | An ''object'' is a set of named ''object member predicates'' together with a set of ''supported'' interfaces. Objects also have state, but this state can only be observed and changed through member predicates; the state is therefore ''encapsulated'' in the object. | ||
===== Interface ===== | ===== Interface ===== | ||
An ''interface'' is an object type. | An ''interface'' is an object type. It has a name and defines a set of named object predicates. | ||
Interfaces | Interfaces form a ''supports'' hierarchy (a [[wikipedia:semilattice|semi-lattice]]) rooted at the <vp>object</vp> interface. If an object has a type denoted by some interface, it also has the types of all supported interfaces. Thus the supports hierarchy is a type hierarchy: an interface is a subtype of each interface it supports. | ||
===== Class ===== | ===== Class ===== | ||
A ''class'' is a named object factory; it | A ''class'' is a named object factory; it constructs objects that correspond to a given interface. If a class constructs objects of interface <vp>iii</vp>, then its objects are "<vp>iii</vp> objects". All objects constructed by the same class share the same definitions of the object member predicates, but each object has its own state; the predicate definitions belong to the class, while the state belongs to each object. | ||
All objects | |||
The set of object member predicates a class ''defines'' is the '''union''' of the predicates ''declared'' (transitively) in its interfaces. If the same predicate is declared in multiple interfaces, the class provides '''one''' common definition; this is only valid if the intended semantics coincide. Interface support must be specified explicitly. | |||
===== Module ===== | ===== Module ===== | ||
A class need not construct objects. A class without a construction type acts as a module: it may have only class members and class state. | |||
===== Identity ===== | ===== Identity ===== | ||
Every object is unique | Every object is unique. Even if two objects currently have identical state, they are not identical: one can be changed without affecting the other. We never access object state directly; we access it through references, and many references may denote the same object. Classes and interfaces are also unique and identified by name (with namespace); duplicate names are not allowed within a program. Structural equality does '''not''' imply identity for objects, classes, or interfaces. | ||
We never | |||
Classes and interfaces are also unique | |||
==== Internal View ==== | ==== Internal View ==== | ||
This section complements the external view with internal aspects: how declarations and implementations are organized. From a programmatic point of view, classes are central (they contain the code). Interfaces have mainly static importance and have no direct runtime representation; objects are dynamic and exist only when the program runs. | |||
From a programmatic point of view, classes are | |||
Interfaces mainly | |||
A class has a declaration and an implementation. The declaration states the ''public'' accessible parts of the class and of the objects it constructs; the implementation ''defines'' what the declaration introduces (predicates are implemented by clauses, by inheritance, or resolved to external libraries). A class declaration is purely declarative. | |||
An implementation can declare additional private entities (domains, predicates, etc.). Object state is stored as facts in the implementation; such facts are per-object, while ''class'' facts are shared across all objects of the class. Facts are declared only in implementations and are not directly accessible from outside. Implementations may also (privately) support more interfaces than stated in the declaration. | |||
===== Code Inheritance ===== | ===== Code Inheritance ===== | ||
Code inheritance occurs only in class implementations. Visual Prolog supports multiple inheritance via an ''inherits'' section in the implementation. The classes you inherit from are ''parent'' (''super'') classes; the inheriting class is the ''child'' (''sub'') class. A child class can only access its parent classes through their public interfaces; it receives no special privileges. | |||
<noinclude>{{LanguageReferenceSubarticle|Basic Concepts/Object System}}</noinclude> |
Latest revision as of 14:26, 20 August 2025
External View
This section clarifies the class-related notions in Visual Prolog at a conceptual level. It does not discuss syntax or implementation details.
The class concept in Visual Prolog is based on three semantic entities:
- objects
- interfaces
- classes
Object
An object is a set of named object member predicates together with a set of supported interfaces. Objects also have state, but this state can only be observed and changed through member predicates; the state is therefore encapsulated in the object.
Interface
An interface is an object type. It has a name and defines a set of named object predicates.
Interfaces form a supports hierarchy (a semi-lattice) rooted at the object interface. If an object has a type denoted by some interface, it also has the types of all supported interfaces. Thus the supports hierarchy is a type hierarchy: an interface is a subtype of each interface it supports.
Class
A class is a named object factory; it constructs objects that correspond to a given interface. If a class constructs objects of interface iii, then its objects are "iii objects". All objects constructed by the same class share the same definitions of the object member predicates, but each object has its own state; the predicate definitions belong to the class, while the state belongs to each object.
The set of object member predicates a class defines is the union of the predicates declared (transitively) in its interfaces. If the same predicate is declared in multiple interfaces, the class provides one common definition; this is only valid if the intended semantics coincide. Interface support must be specified explicitly.
Module
A class need not construct objects. A class without a construction type acts as a module: it may have only class members and class state.
Identity
Every object is unique. Even if two objects currently have identical state, they are not identical: one can be changed without affecting the other. We never access object state directly; we access it through references, and many references may denote the same object. Classes and interfaces are also unique and identified by name (with namespace); duplicate names are not allowed within a program. Structural equality does not imply identity for objects, classes, or interfaces.
Internal View
This section complements the external view with internal aspects: how declarations and implementations are organized. From a programmatic point of view, classes are central (they contain the code). Interfaces have mainly static importance and have no direct runtime representation; objects are dynamic and exist only when the program runs.
A class has a declaration and an implementation. The declaration states the public accessible parts of the class and of the objects it constructs; the implementation defines what the declaration introduces (predicates are implemented by clauses, by inheritance, or resolved to external libraries). A class declaration is purely declarative.
An implementation can declare additional private entities (domains, predicates, etc.). Object state is stored as facts in the implementation; such facts are per-object, while class facts are shared across all objects of the class. Facts are declared only in implementations and are not directly accessible from outside. Implementations may also (privately) support more interfaces than stated in the declaration.
Code Inheritance
Code inheritance occurs only in class implementations. Visual Prolog supports multiple inheritance via an inherits section in the implementation. The classes you inherit from are parent (super) classes; the inheriting class is the child (sub) class. A child class can only access its parent classes through their public interfaces; it receives no special privileges.