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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Stackable Traits Pattern in Scala

32 点作者 saheb37超过 9 年前

5 条评论

lmm超过 9 年前
I like the way Scala solves the problem with multiple inheritance as described in <a href="https:&#x2F;&#x2F;fuhm.net&#x2F;super-harmful&#x2F;" rel="nofollow">https:&#x2F;&#x2F;fuhm.net&#x2F;super-harmful&#x2F;</a> : multiple inheritance is allowed, but only classes (not traits) may have constructors, and a class may only have one parent class (i.e. only one parent with a constructor).<p>For my part I still prefer composition over inheritance and prefer to do composition &quot;by hand&quot; (i.e. explicit members and delegation) where necessary; I wouldn&#x27;t use this style at all. But Scala&#x27;s great strength (and great weakness) is that it has absolutely first-class support for traditional OO like this as well as all the functional stuff.
评论 #11103794 未加载
brandonmenc超过 9 年前
&gt; The example is based on characters of Game of Thrones, to make understanding concepts less boring.<p>For those of us who don&#x27;t know anything about Game of Thrones, and can&#x27;t pronounce Elvish names, the example in this article reads like:<p>Flarg → Twipptch → Glorp → Boop → Fwyxnth → AnyRef → Any<p>So instead of being less boring, I have to use a decoder ring to figure out what&#x27;s going on here.
评论 #11108171 未加载
评论 #11104408 未加载
oselhn超过 9 年前
I think that it does not make sense that Jamie extends Tywin etc. This is not &quot;is a&quot; relation.
评论 #11103768 未加载
评论 #11108210 未加载
评论 #11104578 未加载
评论 #11103750 未加载
joefkelley超过 9 年前
This seems like more of an antipattern to me. If you have to be thinking about linearization order, your hierarchy is probably too complex.
评论 #11108179 未加载
评论 #11105596 未加载
jbooth超过 9 年前
Alternate view:<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Composition_over_inheritance" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Composition_over_inheritance</a>
评论 #11106371 未加载