3 ms·
Need? No. Everything beyond machine code is sugar. Can certain things be solved neatly with inheritance in a given language? Sure. Is it a hammer for every na
by magicalhippo 4y ago
Need? No. Everything beyond machine code is sugar.
Can certain things be solved neatly with inheritance in a given language? Sure.
Is it a hammer for every nail? No.
For example, at work we use Delphi. Delphi has fairly excellent support for COM-like interfaces[1]. I prefer using interfaces, and I prefer to use composition where it makes sense, since Delphi has support for delegation[2].
But when implementing certain interfaces I might use inheritance through a base class with one or two abstract methods.
Could I have done the same through composition? Absolutely, but sometimes using inheritance leads to a smoother implementation. To me this is a happy middle ground, in Delphi. The resulting hierarchy is very shallow, almost never more than two levels. And the users are shielded from this implementation detail through the interface.
[1]: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Object_Interfaces_(Delphi) https://docwiki.embarcadero.com/RADStudio/Sydney/en/Object_I...
[2]: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_Implements_for_Delegation https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_Im...