root/trunk/examples/diamonds/diamond1.lgt

Revision 4601, 1.0 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, the inherited definition which will be used in the 
6bottom object is determined by the Logtalk predicate lookup algorithm.
7*/
8
9
10% root object, declaring and defining a predicate m/0:
11
12:- object(a1).
13
14    :- public(m/0).
15
16    m :-
17        this(This),
18        write('Default definition of method m/0 in object '),
19        write(This), nl.
20
21:- end_object.
22
23
24% an object descending from the root object, which redefines predicate m/0:
25
26:- object(b1,
27    extends(a1)).
28
29    m :-
30        this(This),
31        write('Redefinition of method m/0 in object '),
32        write(This), nl.
33
34:- end_object.
35
36
37% another object descending from the root object, which also redefines predicate m/0:
38
39:- object(c1,
40    extends(a1)).
41
42    m :-
43        this(This),
44        write('Redefinition of method m/0 in object '),
45        write(This), nl.
46
47:- end_object.
48
49
50% bottom object, descending from the two previous objects and, as such, inheriting
51% two definitions for the predicate m/0:
52
53:- object(d1,
54    extends(b1, c1)).
55
56
57:- end_object.
Note: See TracBrowser for help on using the browser.