72b037275f
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1288 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
58 lines
1.0 KiB
Plaintext
58 lines
1.0 KiB
Plaintext
/*
|
|
These objects illustrate a variant of the "diamond problem" using
|
|
a prototype hierarchy.
|
|
|
|
In this simple case, the inherited definition which will be used in the
|
|
bottom object is determined by the Logtalk predicate lookup algorithm.
|
|
*/
|
|
|
|
|
|
% root object, declaring and defining a predicate m/0:
|
|
|
|
:- object(a1).
|
|
|
|
:- 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(b1,
|
|
extends(a1)).
|
|
|
|
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(c1,
|
|
extends(a1)).
|
|
|
|
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:
|
|
|
|
:- object(d1,
|
|
extends(b1, c1)).
|
|
|
|
|
|
:- end_object.
|