Entity Inheritance
Entities can inherit properties and functions from other entities, like subclassing in Object-Oriented programming.
Example:
entity Sub : Super {
str :: String
}
entity Super {
i :: Int
}
function test(){
var e1 := Sub{ i := 1 str := "sdf" };
var e2 := Super{ i := 1 };
}
Subclass entities can be passed whenever an argument of one of its super types is expected.
Example:
function test(){
var e1 := Sub{ i := 1 str := "sdf" };
test(e1);
}
function test(s:Super){
log(s.i);
}
Checking the dynamic type of an entity can be done using isa and casting is performed using as.
Example:
function test(s:Super){
if(s isa Sub){
var su :Sub := s as Sub;
log(su.str);
}
}
