Composition over inheritance: Difference between revisions

Content deleted Content added
Line 74:
* class {{code|Trap}} - which is {{code|Solid}}, but neither {{code|Visible}} nor {{code|Movable}}
 
Note that multiple inheritance is dangerous if not implemented carefully, asbecause it can lead to the [[Multiple inheritance#The diamond problem|diamond problem]]. One solution to avoid this is to create classes such as {{code|VisibleAndSolid}}, {{code|VisibleAndMovable}}, {{code|VisibleAndSolidAndMovable}}, etc. for every needed combination,; thoughhowever, this leads to a large amount of repetitive code. C++ solvesuses [[virtual inheritance]] to solve the diamond problem of multiple inheritance by allowing [[virtual inheritance]].
 
===Composition and interfaces===