Object Orient
You twill find define a type in elz is easy.
Type
Add a ability for a type is also easy.
type Car (
name: str
p: num
)
impl Car {
name() -> str {
return self.name
}
price() -> num {
return self.price
}
}
fn main() {
let c = Car(name: "Tesla", p: 100000)
println("{c.name()}") // "Tesla"
println("{c.price()}") // 100000
}
So easy, right.
Elz has a strict syntax. You can not trying to access properties of type.
This part will be more clear when we go to module.
Trait
trait is requirement of type method.
trait machine {
work()
}
That's mean, if you impl this trait. You have to impl a method call work()
type car (
name: str
price: num
)
impl car: machine {
work() { /* ... */ }
}
What about exportor?
In elz, if trait say that should be export, then impl have to follow it as unexport it.
trait Format {
+string() -> str
}
type Worker (
name: str
salary: num
)
impl Worker: Format {
+string() -> str {
return name + salary.toStr()
}
// string() -> str this won't work, obviously it won't work.
}