Interfaces define strict API contracts that implementing classes must fully satisfy.
Use the interface keyword. Interfaces only contain method signatures and cannot hold properties or default method implementations:
interface FileSystem
do read(path)
do write(path, data)
end
Classes declare compliance to interfaces using the with keyword. If a class fails to implement all methods specified in the interface, a compile-time error (TSE0320) is thrown:
class LocalFS with FileSystem
do read(path)
send fs.read(path)
end
do write(path, data)
fs.write(path, data)
end
end
- Interfaces represent a strict contract: all declared methods must be implemented by the class. No state or method definitions are allowed.
- Traits allow shared method definitions with default implementations, serving as reusable mixins.