Rune - Content-locking work 1/2
[rune.git] / tests / interface.d
1 #!/usr/local/bin/rune -x
2 #
3 #       Demonstrate an interface (multiple inheritance)
4
5 limport "sys";
6 import "stdio";
7
8 alias stdio.File *stdout = stdio.stdout;
9
10 # sample class
11 #
12
13 class HashableListNode {
14         interface ListNode lnode;
15         interface HashNode hnode;
16 }
17
18 class HashableList {
19         int a;
20         int b;
21
22         # An 'interface' combines a named declaration with an unnamed subclass
23         # definition and also allows a pointer to our class (HashableList)
24         # to be cast to a pointer to the subclass (list in this case).
25         #
26         interface List list {
27                 refine method
28                 void addTail(HashableListNode @node)
29                 {
30                         super.addTail(node);
31                         hash.super.addHash(node);
32                 }
33                 ...
34         }
35         interface Hash hash {
36                 refine method void
37                 addHash(HashableListNode @node)
38                 {
39                         super.addHash(node);
40                         list.super.addTail(node);
41                 }
42         }
43 }