Go to the first, previous, next, last section, table of contents.


Using OCIAO objects

Author(s): Angel Fernandez Pineda.

Version: 1.3#124 (1999/11/27, 4:4:5 MET)

Version of last change: 1.3#78 (1999/10/13, 18:31:8 MEST)

This package is required to enable user code to create objects and manipulate them, as well as loading any needed class.

Usage and interface (objects)

Documentation on new declarations (objects)

DECLARATION: use_class/1:

It establishes an usage relationship between the given file (which is supposed to declare a class) and current source. Usage relationships are needed in order to enable code to create instances of the given class, and to make calls to instances derived from such class.

Since an interface is some kind of class, they may be used within this declaration but only for semantic checking porpouses. Instances will not be derived from interfaces.

use_class/1 is used in the same way as use_module/1.

Usage: :- use_class(ClassSource).

DECLARATION: instance_of/2:

Statically declares an identifier to be an instance of a given class.

It may be used as new/2 predicate except for:

For every statically declared object the given constructor will be called at program startup. Those instances may be destroyed manually, but it is not recommended.

When reloading the involved class from the CIAO toplevel shell. It may destroy statically declared instances, and create them again.

Statically declared instances must be called using a specifically designed module-qualification: ClassName(Object):Goal. For example:

    :- module(example,[main/0],[objects]).
    :- use_class(library(counter)).
    :- cnt instance_of counter(10).

    main :-
         counter(cnt):decrease(1),
         counter(cnt):current_value(X),
         display(X).

But statically written code (only) is allowed to use module-style qualifications as a macro:

    main :-
         cnt:decrease(1),
         cnt:current_value(X),
         display(X).

Notice that dynamically expanded goals such as X=cnt,X:decrease(1) will not work, use X=counter(cnt),X:decrease(1) instead.

Usage: :- instance_of(Object,Constructor).

DECLARATION: new/2:

This declaration has the same effect as instance_of/2.

Usage: :- new(Object,Constructor).

Documentation on exports (objects)

PROPERTY: class_source/1:

Usage: class_source(Source)

PROPERTY: constructor/1:

Usage: constructor(Cons)

PROPERTY: instance_id/1:

Usage: instance_id(ID)

PROPERTY: class_name/1:

Usage: class_name(ClassName)

PREDICATE: use_class/1:

It establishes an usage relationship between the given file (which is supposed to declare a class) and current source. Usage relationships are needed in order to enable code to create instances of the given class, and to make calls to instances derived from such class.

Since an interface is some kind of class, they may be used within this declaration but only for semantic checking porpouses. Instances will not be derived from interfaces.

use_class/1 is used in the same way as use_module/1.

PREDICATE: instance_of/2:

Statically declares an identifier to be an instance of a given class.

It may be used as new/2 predicate except for:

For every statically declared object the given constructor will be called at program startup. Those instances may be destroyed manually, but it is not recommended.

When reloading the involved class from the CIAO toplevel shell. It may destroy statically declared instances, and create them again.

Statically declared instances must be called using a specifically designed module-qualification: ClassName(Object):Goal. For example:

    :- module(example,[main/0],[objects]).
    :- use_class(library(counter)).
    :- cnt instance_of counter(10).

    main :-
         counter(cnt):decrease(1),
         counter(cnt):current_value(X),
         display(X).

But statically written code (only) is allowed to use module-style qualifications as a macro:

    main :-
         cnt:decrease(1),
         cnt:current_value(X),
         display(X).

Notice that dynamically expanded goals such as X=cnt,X:decrease(1) will not work, use X=counter(cnt),X:decrease(1) instead.

PREDICATE: new/2:

This declaration has the same effect as instance_of/2.


Go to the first, previous, next, last section, table of contents.