This problem comes up quite a bit actually. Take this instance model view. I have 2 objects. Simulation object and render object.
The class ObjectRSim (Object, designated as Render Sim) is something like:
class ObjectRSsim {
var simObject:ObjectSim;
}
ObjectRSim, uses properties/invalidation of ObjectSim.
There are objects that inherit ObjectRSim and ObjectSim:
PosObjectRSim and PosObjectSim (positional objects..)
class PosObjectRSim extends ObjectRSim {
var posSimObject:PosObjectSim;
}
or…
class ObjectRSim {
var simObject:Dynamic; //Dynamic is untyped Type from haxe, the compiler does not check calls to a Dynamic object.
}
Should I have a reference to each type in the inheritance hierarchy of ObjectSim in the ObjectRSim hierarchy classes, or should I just use simObject:Dynamic?
It will be totally wrong to use Dynamic for that case. It’s frequently slow(for every haxe target except javascript I guess), not inlined, and is normally used only for interacting with underlying platform or working with serialization(YAML, JSON etc.).
Talking about solving the problem…
If there aren’t thousands of this objects planned, I’d probably just another field for lower-level class object. It’s not the clearest way from OOP perspective, but it frequently results in simpler and clearer code for me.
Casting is another option(I personally don’t like).
Parameterization would probably be the best way to handle that, but I’m not sure if we already have type restricted parameterization in haxe.