Interface in Verse
The interface type provides a contract for how to interact with any class that implements the interface. An interface cannot be instantiated, but a class can inherit from the interface and implement its methods. An interface is similar to an abstract class, except that it does not allow partial implementation or fields as part of the definition.
For example, let’s create an interface for anything that you can ride on, such as a bicycle or a horse:
| | |
| --- | --- |
| | rideable := interface(): |
| | Mount()<decides> : void |
| | Dismount()<decides> : void |
rideable := interface(): Mount()<decides> : void Dismount()<decides> : void
Copy full snippet(3 lines long)
Any classes that inherit the interface must implement the interface’s functions and add the override specifier:
bicycle := class(rideable):
...
Mount<override>()<decides> : void =
...
Dismount<override>()<decides> : void =
...
horse := class(rideable):
...
Mount<override>()<decides> : void =
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.