root/trunk/examples/diamonds/diamond3.lgt

Revision 4601, 1.2 KB (checked in by pmoura, 7 weeks ago)

Added svn:mime-type property to source files (set to text/x-logtalk).

  • Property svn:mime-type set to text/x-logtalk
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2These objects illustrate a variant of the "diamond problem" using
3a prototype hierarchy.
4
5In this simple case, a solution is presented for making two conflicting
6definitions inherited by the bottom object visible through the use of the
7alias/3 predicate directive.
8*/
9
10
11% root object, declaring and defining a predicate m/0:
12
13:- object(a3).
14
15    :- public(m/0).
16
17    m :-
18        this(This),
19        write('Default definition of method m/0 in object '),
20        write(This), nl.
21
22:- end_object.
23
24
25% an object descending from the root object, which redefines predicate m/0:
26
27:- object(b3,
28    extends(a3)).
29
30    m :-
31        this(This),
32        write('Redefinition of method m/0 in object '),
33        write(This), nl.
34
35:- end_object.
36
37
38% another object descending from the root object, which also redefines predicate m/0:
39
40:- object(c3,
41    extends(a3)).
42
43    m :-
44        this(This),
45        write('Redefinition of method m/0 in object '),
46        write(This), nl.
47
48:- end_object.
49
50
51% bottom object, descending from the two previous objects and, as such, inheriting
52% two definitions for the predicate m/0; both inherited definitions are renamed
53% using the alias/3 directive:
54
55:- object(d3,
56    extends(b3, c3)).
57
58    :- alias(b3, m/0, b3_m/0).
59    :- alias(c3, m/0, c3_m/0).
60
61:- end_object.
Note: See TracBrowser for help on using the browser.