If the world was simple,:
If the world is as complex as it is, and without multiple inheritance, you would probably address this kind of challenge with the bridge design pattern. This pattern aims at separating the abstraction and its specializations on one side, and the implementation and its specialization on the other side. The bridge between the two is organized using composition.bridge design pattern:
- This pattern aims at separating the abstraction and its specializations on one side, and the implementation and its specialization on the other side. The bridge between the two is organized using composition.
- But despite it's conceptual beauty, it requires to think well the API and it's a bit cumbersome to use with a lot of boilerplate code to forward the calls from abstraction to implementation.
We could argue about whether we really need MI or not. The point is inBut let's face the reality: in your case that a BtConvexShape IS really BtShape, but; and at the same time it IS really an IConvexShape and also an IShape.
MI allows you to express this complex semantical relationship in a simple manner. It allows also allows to define each behavior where best suits according to thisthe semantic and not where imposed by the language constraints.
The drawback is that MI is difficult for many people to understand. And it comes with conceptual problems related to the diamond: a BtConvexShape object is an IConvexShape which is an IShape object, and at the same time it's a BtShape which is an IShape object. The question is whether we have two independent IShape objects, or if all these IShape always refer to the same.
C++ has normal inheritance and virtual inheritance to make the difference between the two casessecond case well. And your Your example is a typical use case for MI with virtual inheritance. It's exatly what this language feature was designed for ! The
The main issues with the virtual inheritance is that:
SoBut if your design correspond to athe typical case of multiple and virtual inheritance, and if you managed to get it work, go for it. It's like all powerful tools: you just have to be extra-careful and it'll serve you well.