Class Interfaces

Whilst porting some C# code, I’ve had to try to get my head around Xojo’s implementation of class interfaces.

In C#, it would seem that an interface can declare both methods and properties. Can Xojo’s interfaces only declare methods, not properties?

Is it possible to declare an interface (lets call it ‘IBox’) and have some class have a property of type ‘IBox’?

Essentially what I’m trying to duplicate is that there is an interface in the C# code that a class can adhere to that says that that class is a box. The only thing that classes implementing this interface need to have is a property called ‘bb’ that represents a bounding box.

I have a class called ‘Node’ that has a property ‘obj’ that can be any class but that class must adhere to the IBox interface. I’m sure this is doable with some combination of the Auto type and interfaces but this is a murky pat of Xojo that I’ve yet to dabble in. Can anyone help?

method pairs (get / set) can be defined in the interface & behave like properties

Could you please point us to an example?

It’s sounds more involved than it really is. Just add 2 methods with the same name. One takes a parameter (the setter), the other returns a value (the getter). The result acts a lot like a property.

For the setter look up the Assigns keyword in the docs.

Cool thanks

The problem is more that Xojo doesn’t have good helper features to do this and not that it can’t be done. It’s just cumbersome. Also in C# properties autogenerate their backend field to store their value and you don’t need to actually implement the getter/setter. In Xojo you will manually have to create this property and hook it up on every class that implements the interface. If you have a default implementation you can copy and paste the getter/setter methods and the backend property but this definitely becomes a hassle.

From my understanding its because interfaces aren’t suppose to have implementation. Which from a CompSci/Design standpoint is correct. Unfortunately using your limited feedback points to support a feature change to make this more manageable isn’t exactly practical when there are more important features and bugs to fix - meaning these basic improvements often get lost in the dust. :frowning: