This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/instmethods/instmethods.lgt

48 lines
1.0 KiB
Plaintext
Raw Normal View History

:- object(root, % avoid infinite metaclass regression by
instantiates(root)). % making the class its own metaclass
:- public(method/0).
method :-
this(This),
write('This is the default definition for the method, stored in class '),
writeq(This), write('.'), nl.
:- end_object.
:- object(instance1, % this instance simply inherits the method/0 predicate
instantiates(root)).
:- end_object.
:- object(instance2, % this instance provides its own definition for the
instantiates(root)). % method/0 predicate
method :-
this(This),
write('This is an overriding definition stored in the '),
writeq(This),
write(' instance itself.'), nl.
:- end_object.
:- object(instance3, % this instance specializes the inherited definition
instantiates(root)). % of the method/0 predicate
method :-
this(This),
write('This is a specializing definition stored in the '),
writeq(This),
write(' instance itself.'), nl,
write('It makes a super call to execute the default definition:'), nl, nl,
^^method.
:- end_object.