Navigation  without Java Scripts

Class Implementation

Syntax

IMPLEMENT <class_name> [: <base_class_list>]
{DOMAINS <domains_declarations>}
{[STATIC] FACTS <facts_declarations>}
{[STATIC] PREDICATES <predicates_declarations>}
{CLAUSES <predicates_bodies>}
ENDCLASS [<class_name>]
Each class, except abstract classes, must have one and the only one implementation in the project. The class implementation can be placed into any project source file in which the class declaration is visible.

Abstract classes should not have implementations.

The elements of the class implementation syntax are:

All names declared in the class implementation are private.

IMPLEMENT Keyword

The class implementation section begins with the keyword IMPLEMENT. The IMPLEMENT keyword should be followed by the class implementation header that includes the class name and an optional list of base (parent) classes.
< class_name >
The class_name specifies the name of the class. The class name is to be unique within a project.
<base_class_list>
The base class list includes a base (parent) class or classes from which the derived class class_name will inherit public and protected domains, predicates, facts, and clauses. Notice that all inherited names become private. (See example 2).
Each class can be met in this list only once. The class cannot be specified as the base class for itself.
Abstract classes cannot be specified in the implementation base class list.
For example:
IMPLEMENT C : P1, P2

Example

CLASS xclass
PREDICATES
inc
dec
check(string)
ENDCLASS xclass
....
IMPLEMENT xclass
FACTS
single count(INTEGER)
CLAUSES
count(0).
inc:-
count(X),!,
X1=X+1,
assert(count(X1)).
dec:-
count(X),!,
X1=X-1,
assert(count(X1)).
check(Title):-
count(Val),!,
write(Title, Val),nl.
ENDCLASS xclass
GOAL
O = xclass::new, % Creates a new object of the xclass
O:check("Initial value of counter: "),
O:inc,
O:check("New value of counter: "),
O:delete.
See also