Background
I'm creating a GUI that has graphs made of different node types and connections, as well as plots that can be made from the nodes.
My inheritance tree looks like this:
As you can see, all graph nodes and plots are moveable. Plots and some graph nodes are resizeable. Now, I want to let the user to be able to group together all the graph nodes, inside of another node type called a Network
.
So I want to add a method called restrict
to all non-Plot classes, despite the fact they have different base classes.
Question
One approach I've heard about is to use mixins, but they feel like overkill. Is there an easier way to add methods to classes that inherit from different base classes? How do I keep the principle "compositionality over inheritance" in mind in this case?
I don't think I should just add restrict
to Component
as this would create a useless method for Plots
that would never be used and this feels like a bad code smell.
I understand I can use Interfaces for multiple inheritance, but Interfaces don't automatically use the reference implementation, so I'd have to copy a bunch of super
calls into each method definitions. This feels like a lot of code duplication. Is there a way to automatically use the reference implementation from an Interface if no implementation is given by the implementing class?