Interfaces

Interfaces are types that specify a set of member functions. Struct types can implement an interface by listing the interface name after a colon following the struct name, and providing the member functions required by the interface:

interface Foo {
    fun foo(): int;
     
    fun fooDefault(): int { // default function that can be overrided
        return -1; 
    }
}

struct Bar: Foo {
    fun foo(): int {
        return 0;    
    }
    
    fun fooDefault(): int {
        return foo();
    }
}

Last updated