Multiple levels of inheritance on non-persistent entities: bad practice?

0
Hi community, As best practice Mendix recommends not go deeper than 2 levels of inheritence (specializations) for performance reasons (https://docs.mendix.com/howto/general/dev-best-practices). Does that also apply for non-persistent entities? And if so: why? Regards, Johan
asked
2 answers
3

Short answer: This does not apply to non-persistent entities.

Explaination: For persistent entities, the problem is the database design. Each level of inheritance adds an extra table. When you retrieve an object, then all the tables need to be queried every time for access rules. This is where performance really starts to suffer as more levels are added. Bart Tolen sums it up nicely here – https://forum.mendix.com/link/questions/8846

-Andrej

answered
0

Allowing multiple inheritance makes the rules about function overloads and virtual dispatch decidedly more tricky, as well as the language implementation around object layouts. These impact language designers/implementors quite a bit, and raise the already high bar to get a language done, stable and adopted.

 

It is simple to think this way, if class A inherits from multiple classes, then the class A will have the same grandparent class multiple times, this means the code will be complicated and a series of bugs will go unacknowledged. Personally, I think multiple inheritance has a bad rap, and that a well done system of trait style composition would be really powerful/useful... but there are a lot of ways that it can be implemented badly, and a lot of reasons it's not a good idea in a language like C++.

 

answered