Interface Implementation
extend attaches methods to a type, optionally satisfying one or more interfaces.
struct Circle {
radius: float64;
}
extend Circle {
func Area(self) -> float64 {
return Pi * self.radius * self.radius;
}
}
extend Circle: Display {
func ToString(self) -> String {
return Format("Circle: radius = {}", self.radius);
}
}
The compiler verifies that the extend block provides every method the interface declares, with matching signatures. A type may satisfy any number of interfaces.
Once implemented, interface methods are called like any other method:
let c = Circle { radius: 2.0 };
Print(c.ToString()); // Circle: radius = 2
See Also
- Interface Declaration — the signatures an
extendblock must satisfy - Methods — the
extendblock and method syntax - Structures — the types being extended
Declaration
An interface declares a set of method signatures that a type must satisfy. It lists method headers — names, parameters, and return types — but no bodies; the implementing type supplies those.
Overview
Modules organize code into named namespaces. Each aspect of the module system has a dedicated chapter: