5 ms·
The original inspiration for the idea really has nothing whatever to do with its subsequent architectural role, nor with its value as a mechanism. As a perform
by ncmncm 6y ago
The original inspiration for the idea really has nothing whatever to do with its subsequent architectural role, nor with its value as a mechanism.
As a performance optimization, inheritance demonstrated value at a time when performance improvements were at least three orders of magnitude more important than they are today.
People here like to disparage OO and inheritance, but the distaste clearly is just a reaction to Java and its unfortunate lack of any other organizational mechanism, requiring abuse of the one feature for everything.
In C++, it is sometimes directly useful, with or without a vtable, independent of "OO"; and even occasionally is exactly the right thing, explicitly as an OO tool. As one tool in the toolbox, it is simple, understandable, and causes no trouble unless badly abused. It is far from the only tool, so is not often the best choice, but probably most programs of any substance have one or two places where it is better used than not.
- cout 6y agoIME the problem with inheritance in C++ is that it is so easy programmers reach for it instinctively, even when another tool might be a better choice in the long term. I definitely use inheritance in my c++ code, but as I've grown (and as the language has grown) I've found myself using it less and less. Perhaps that's the way it's supposed to be.
- ncmncm 6y agoIt is a problem with teaching. If you are taught to imagine yourself as an OO programmer using an OO language to produce OO designs, you will shoehorn in OO mechanisms even where they fit poorly. C++ has other organizational tools for these cases, so that there is little natural temptation to abuse OO for them. People coming to C++ from impoverished languages like Java often fail to recognize bad habits they have internalized.
- zozbot234 6y agoImplementation inheritance is indeed problematic, no matter how it's used. The defining feature of implementation inheritance is that any code, relating to any class in the hierarchy, can rely on methods that may then be overridden in unpredictable ways further down in the hierarchy. If you don't need or expect this behavior, you can use composition and delegation instead - which come with a far simpler semantics and do a way better job of preserving modularity.
- ncmncm 6y agoImplementation inheritance is absolutely no problem within a project or component that entirely controls both base and derived classes, where it amounts to, simply, a notational convenience. It is not, then, a "good OO design"; but there is nothing sacred about OO. Ultimately, any combination of well-specified mechanisms may be correctly used to achieve an elegant design, regardless of formal architectural conventions. The reason a feature was introduced into a language has no necessary connection to reasons for using it. Implementation inheritance is a problem when crossing organizational boundaries, as reasonable changes upstream can impact correctness downstream. Ultimately, there is no substitute for taste. Substituting fetishism produces unfortunate results.