TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why People Misuse Inheritance

2 点作者 memorable大约 2 年前

1 comment

magicalhippo大约 2 年前
<i>I expect that in a language that has such blessed, boilerplate-free delegation tools, inheritance will be less overused.</i><p>Delphi has support for delegation[1], but sadly not partial delegation.<p>However it doesn&#x27;t seem like a big thing, compiler-wise, in a language like Delphi or C# to support partial delegation. You could then have one line saying that by default all calls are delegated to a given instance, a member&#x2F;field or similar, and the compiler could then just automatically generate the forwarding calls for the methods you don&#x27;t implement explicitly.<p>But wait... this is starting to smell a lot like inheritance! There the compiler automatically handles the delegation of the calls to the base class unless you override.<p>Of course there&#x27;s still a big difference, in that typically inheritance is bidirectional while delegation is unidirectional.<p>[1]: <a href="https:&#x2F;&#x2F;docwiki.embarcadero.com&#x2F;RADStudio&#x2F;Sydney&#x2F;en&#x2F;Using_Implements_for_Delegation" rel="nofollow">https:&#x2F;&#x2F;docwiki.embarcadero.com&#x2F;RADStudio&#x2F;Sydney&#x2F;en&#x2F;Using_Im...</a>