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/diamond3.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

62 lines
1.2 KiB
Plaintext

/*
These metafile objects illustrate a variant of the "diamond problem" using
a prototype hierarchy.
In this simple case, a solution is presented for making two conflicting
definitions inherited by the bottom object visible through the use of the
alias/3 predicate directive.
*/
% root object, declaring and defining a predicate m/0:
:- object(a3).
:- 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(b3,
extends(a3)).
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(c3,
extends(a3)).
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; both inherited definitions are renamed
% using the alias/3 directive:
:- object(d3,
extends(b3, c3)).
:- alias(b3, m/0, b3_m/0).
:- alias(c3, m/0, c3_m/0).
:- end_object.