aboutsummaryrefslogtreecommitdiff
path: root/notes/interfaces.txt
blob: de9b43ce569a66ce45353cb2c5fdb6e652fae80d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

Types of interfaces
-------------------

Explicit interfaces:
* Used in: Java, C#, ...
* Compatibility: Same interface needs to be implemented.

Implicit interfaces:
* Used in: Go
* Compatibility: All declared method names/paramas need to match

Duck typing:
* Used in: Python
* Compatibility: All used method names/params need to match

Decoupled interfaces via function pointers:
* Used in: C
* Compatibility: Methods can be mixed & matched, as long as types match


Ideas
-----
Make it possible to define a "translation" from a class to an interface?
The translation could go either into a class or separately.

Example:

Openable.slul:

    interface   # Must come first in the source file

    func open
        bool keep_open
    end

Box.slul:

    implements Openable

    func open
        bool keep_open
    code
        ...
    end


Bottle.slul:

    func pop
        bool leave_cap_off
    code
        ...
    end

LockedDoor.slul:

    func open
        Key key
        bool leave_open
    code
        ...
    end

UseInterfaces.slul:


    func test
    code
        open_thing box
        # How to solve these two?
        open_thing bottle
        open_thing locked_door
    end