我有一个特性I
(中介者),一个将该特性混入的类M
(混合器)和一个特性S
(具体特性)。
class M extends Something with S {
def baz() = foo()
}
trait I {
def foo(): { ...; bar(); ... }
def bar()
}
trait S extends I {
def bar() = 42
}
I
作为M
和S
之间的中间层,提供一个通用接口。
我在I
中实现了一个方法foo
,它调用了一个方法bar
(I
中未实现但已定义)。我想要实现的是,所有扩展I
的特性必须实现bar
,这样会因为bar
未实现而在编译时引发错误:
trait Z extends I
这在Scala中可能吗?
附言:我知道强制Scala trait实现特定方法的答案,但我不想使用这种显式耦合方式。
trait
去实现那样的东西。 - Dave L.