I am trying to make a simple extendable class and then extend it and then place the instances of the extended classes into a variable and then call the extended classes overriden methods. In other languages this is known as virtual methods. I am unable to find any information about this in Haxe.
class Shape
{
public virtual function DrawShape(): Void {}
}
class Triangle extends Shape
{
public virtual function DrawShape(): Void { printf("Triangle"); }
}
class Square extends Shape
{
public virtual function DrawShape(): Void { printf("Square"); }
}
//usage
var myShape : Shape;
//As Triangle
myShape = new Triangle();
myShape.DrawShape(); //outputs Triangle, even though it is type Shape variable
//As Square
myShape = new Square();
myShape.DrawShape(); //outputs Square, even though it is type Shape variable
So, if anyonw knows how to do this in Haxe please help. Thanks.
virtual == override in Haxe language