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
pmoura 3455276aa2 Logtalk 2.26.2 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1487 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2005-12-24 18:07:41 +00:00

48 lines
1.0 KiB
Plaintext

:- 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.