COMMUNITY

Overly strict interfaces vis-a-vis property accessors


#1

FWIW: I’m new to Haxe, through hacking on someone else’s project.

It doesn’t seem possible to have an interface be agnostic as to a property’s get/set behavior. That is to say, if I want an interface that exposes the ability to read property x, from an outside perspective I don’t care if the class implements x as default or get. Similarly for set. As long as I can get or set the property from outside, that ideally would be enough to satisfy the interface, but that doesn’t seem to be the case. If I want to use get or set in a class, it has to be in the interface, which means I have to use get or set in every class that implements that interface.

I suppose I was hoping it were more similar to Swift in this regard, where the interface just specifies whether you can read or read/write, and the implementing class can expose that as either stored or computed properties.

Anyone have insight into the design choices, here?


(Simon Krajewski) #2

This doesn’t make any sense in Haxe because properties are a compile-time feature, whereas interface fields are accessed at run-time via dynamic dispatch.