Skip to content
🚧 This feature is coming soon and is not yet available.

Interfaces

Planned Features

Interface Declaration

Define contracts that classes must implement:

interface Printable {
print(): void;
}
interface Comparable {
compareTo(other: Comparable): i32;
}

Implementing Interfaces

Classes can implement one or more interfaces:

interface Shape {
area(): f64;
perimeter(): f64;
}
class Rectangle implements Shape {
public width: f64;
public height: f64;
constructor(w: f64, h: f64) {
this.width = w;
this.height = h;
}
public area(): f64 {
return this.width * this.height;
}
public perimeter(): f64 {
return 2.0 * (this.width + this.height);
}
}

Multiple Interfaces

A class can implement multiple interfaces:

interface Drawable {
draw(): void;
}
interface Clickable {
onClick(): void;
}
class Button implements Drawable, Clickable {
public draw(): void {
// Render the button
}
public onClick(): void {
// Handle click
}
}

Interface as Type

Use interfaces as variable and parameter types:

function calculateTotalArea(shapes: Shape[]): f64 {
let total: f64 = 0.0;
let i: i32 = 0;
while (i < shapes.length()) {
total = total + shapes.get(i).area();
i = i + 1;
}
return total;
}

Use Cases

Dependency Injection

interface Logger {
log(message: string): void;
}
class ConsoleLogger implements Logger {
public log(message: string): void {
// Print to console
}
}
class FileLogger implements Logger {
public log(message: string): void {
// Write to file
}
}
class Application {
private logger: Logger;
constructor(logger: Logger) {
this.logger = logger;
}
}

Plugin Systems

interface Plugin {
getName(): string;
execute(): void;
}
function runPlugins(plugins: Plugin[]): void {
let i: i32 = 0;
while (i < plugins.length()) {
plugins.get(i).execute();
i = i + 1;
}
}

Roadmap

FeatureStatus
Interface declarationPlanned
implements keywordPlanned
Multiple interfacesPlanned
Interface as typePlanned
Default methodsConsidered

Stay updated on GitHub!