3
假设我有多个trait
s,每个特征都会向延伸Actor
的类添加一些行为。定义将特定行为添加到实现特定特征的类的多个特征的最佳实践
它们每个都需要Actor
上的一小部分方法。他们都可以像这样延长Actor
吗?
trait A extends Actor {
def doAThing = { ... }
}
trait B extends Actor {
def doBThing = { ... }
}
trait C extends Actor {
def doCThing = { ... }
}
class D extends Actor with A with B with C
还是应该每个性状限定它需要从Actor
作为抽象方法,使得它们被最后,混凝土类,这是唯一的一个,然后,将延长Actor
供给的方法呢?
请参阅[scala自我类型和特质子类之间有什么区别?](http://stackoverflow.com/questions/1990948/what-is-the-difference-between-scala-self-types-and-特质的子类)。这可能是你在找什么。 – 4e6 2012-03-28 12:02:35
我认为这就是我正在寻找的东西。谢谢! – Russell 2012-03-28 12:10:09
我根本不知道自我类型 - 如果你认为这个问题是一条不同的路径来回答相同的答案,那么发布它,我会接受它。 – Russell 2012-03-28 12:12:50