Can I overimplement vala getters?

So, I don’t actually know where do I ask this… Can I have just a field with getter in an interface and then have both { get; set; } in the implementation? Sounds like normal behavior of getters and setters as methods, but I’m getting this error, error: Type and/or accessors of inherited properties 'SomeThing.the_property' and 'MyThing.the_property' do not match: incompatible set accessor.

Is it even possible to do that overimplementation without get_ & set_ methods?

1 Like

Also, regular fields without that { get; set; } thing, If you think about it, should be considered as implementing my interface’s { get; }, but for some reason they’re not.

Is the compiler not so object-oriented with getters or am I doing something wrong?

I’m not coming from a world of getters and setters, but I’m failing to understand why you’d want not to have the setter of your variable appear in the interface. Could you explain a bit what you’re trying to achieve?

Sorry, forgot to include this: I have a lot of API interfaces, (like a header file) and they sometimes require to implement just the getter, so the compiler will prevent the API user from messing up internal implementation’s state. But the implementation classes (like source files) internally do change the get-only fields, for example to initialize them.

What I actually may need is typescript’s “readonly” field modifier, that allows the implementors to change readonly fields but the interface users can just read them.

Isn’t that the role of the public vs. internal keywords, to allow external code to access or not a method? Wouldn’t something like:

public abstract bool test { public get; internal set; }

work? I’ve never tried, might be interesting.

1 Like

Wait, does that exist? I’m gonna test it now

It’s worked! Thank you, I’ve marked it as the solution