12.3. Interfaces
The INTERFACES module implements interface-based polymorphism for daslang.
It provides the [interface] annotation for defining abstract interfaces
with virtual method tables, supporting multiple implementations and dynamic
dispatch without class inheritance.
Features:
Interface inheritance (
class IChild : IParent)Default method implementations (non-abstract methods)
Compile-time completeness checking (error 30111 on missing methods)
is/as/?asoperators via theInterfaceAsIsvariant macroConst-only interfaces — when all methods are
def const,as/?as/iswork on const pointers
All functions and symbols are in “interfaces” module, use require to get access to it.
require daslib/interfaces
Example:
require daslib/interfaces
[interface]
class IGreeter {
def abstract greet(name : string) : string
}
[implements(IGreeter)]
class MyGreeter {
def IGreeter`greet(name : string) : string {
return "Hello, {name}!"
}
}
[export]
def main() {
var obj = new MyGreeter()
var greeter = obj as IGreeter
print("{greeter->greet("world")}\n")
}
// output: Hello, world!
See also: Interfaces tutorial for a complete walkthrough.
12.3.1. Variant macros
- InterfaceAsIs
Variant macro that enables is, as, and ?as operators for interface types declared with [interface] / [implements].
12.3.2. Structure macros
- interface
Verifies that the annotated class is a valid interface — it may only contain
function-typed fields (no data members). Applied via [interface] annotation.
- implements
Generates interface bindings for a struct. Creates a proxy class that delegates interface method calls to the struct’s own methods, and adds a get`InterfaceName method that lazily constructs the proxy. Applied via [implements(InterfaceName)].