Assingn interface to base class?

Is there a way to assign an interface to a base class and have it enforced for subclasses?

No, you must remember to implement the interface in subclasses.
Alternatively, you can make subclass of the base class (e.g PushButton) and add to it the interface.
Then you will have to remember to only subclass your PushButton subclass.

You can enforce it one level down by having the methods in the base class raise an exception. If the subclass doesn’t implement the method, you throw the exception.

Bummer, because that requires the discipline to remember to implement the interface instead of the base class enforcing it, a recipe for failure.

In the base class have it’s implementation of the methods for the interface simply raise an exception
Anything NOT overridden by a subclass will then just raise an exception
It’s all done at runtime not compile time though

That seems like it could work.

Gonna play with that a bit and see how it works out with some polymorphism thrown in.

Is there a reason interfaces don’t/cant work from the base class? Seem like it would be a nice feature.


They do - the base class implements the interface and anything that inherits from it will as well because they inherit that implementation.

Requiring that subclasses override the base class implementation has nothing to do with it being an interface.

Hmm, I’m thinking what I didn’t factor in was that you can have multiple interfaces, and xojo doesn’t support multiple inheritance.


Correct - Xojo does not support multiple inheritance