Protocols provide a way to achieve duck typing in Gosu without sacrificing static verification. This functionality is achieved by introducing Protocol Types into Gosu via The Open Type System.
SyntaxProtocols are defined in files ending in the .proto suffix. An example protocol definition is:
This protocol can now be used like so:
The two classes above, which both have an aFunction():String method defined, both satisfy the protocol definition and, thus, can be assigned to the protocol variable. This is despite the fact that the two types are totally unrelated. If either class didn't have aFunction():String defined then the code above would have a compilation error: the Protocol type verifies that the other type conforms to it at the point of assignment.