jeudi 18 mai 2017

Is multiple inheritance a good design pattern in my case?

I have the following problem: I want to have multiple Windows all displaying some kind of function graphs. Say one window should show a Coordinate Axis and have some interaction features, another window should also display a coordinate axis and have a settings dialog.

How I intuitively would go about this, is to implement Window as some class which does the initialization of the basic window with my framework (in my case VTK), some virtual inherited classes WindowWithAxis, WindowInteracting, WindowWithSettingsDialog and then have

  • class A inherit WindowInteracting and WindowCoordinateAxis
  • class B inherit WindowWithSettingsDialog and WindowCoordinateAxis

So reading through the internet I now saw everywhere (for example the Google Style Guide), that I only should do this if Window, WindowInteracting, WindowCoordinateAxis, WindowWithSettingsDialog are all pure abstract classes/interfaces.

And this is what I don't understand. Doesn't this mean that I am not allowed to actually implement these classes and that I will have to implement all the functionality of Window and of WindowCoordinateAxisin class A and class B (and every other class which uses these)? That seems not like a clean solution to me.

This kind of "Diamond shaped Inheritance" should be a problem that occurs quite often, so what are the ways in which I can approach this?

Aucun commentaire:

Enregistrer un commentaire