Skip to content

Interfaces

Interace is an abstration that defines what a class can do without specifying how to do it. It consists of a set of a abstract methods.

The following example defines an interface that serves as a contract for any entity requring authentication.

interface Authenticatable {
// Validate the provided credential
fn login(password: string) -> bool
}

To implement an interface use the : Interface syntax in class declaration:

class User(
var name: string,
priv var passwordHash: string
) : Authenticatable {
fn login(password: string) -> bool {
return secureHash(password) == password
}
}