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/diamonds/diamond2.mlgt
pmoura 921e576877 Logtalk 2.21.0 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1138 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2004-09-14 23:11:12 +00:00

65 lines
1.3 KiB
Plaintext

/*
These metafile objects illustrate a variant of the "diamond problem" using
a prototype hierarchy.
In this simple case, a solution for making the overridden definition inherited
by the bottom object the visible one is implemented using the alias/3 predicate
directive.
*/
% root object, declaring and defining a predicate m/0:
:- object(a2).
:- public(m/0).
m :-
this(This),
write('Default definition of method m/0 in object '),
write(This), nl.
:- end_object.
% an object descending from the root object, which redefines predicate m/0:
:- object(b2,
extends(a2)).
m :-
this(This),
write('Redefinition of method m/0 in object '),
write(This), nl.
:- end_object.
% another object descending from the root object, which also redefines predicate m/0:
:- object(c2,
extends(a2)).
m :-
this(This),
write('Redefinition of method m/0 in object '),
write(This), nl.
:- end_object.
% bottom object, descending from the two previous objects and, as such, inheriting
% two definitions for the predicate m/0; the overridden definition inherited from
% object "c2" is renamed using the alias/3 directive and then we redefined the
% predicate m/0 to call the renamed definition:
:- object(d2,
extends(b2, c2)).
:- alias(c2, m/0, c2_m/0).
m :-
::c2_m.
:- end_object.