我想要有一些只能混合指定特性的类:
class Peter extends Human with Lawful with Evil
class Mag extends Elf with Chaotic with Neutral
在Scala中有一种方法可以做到这一点吗?
更新:
trait Law
trait Lawful extends Law
trait LNeutral extends Law
trait Chaotic extends Law
trait Moral
trait Good extends Moral
trait Neutral extends Moral
trait Evil extends Moral
class Hero .........
class Homer extends Hero with Chaotic with Good
我想以一种方式定义一个Hero
类,以便约束客户端程序员在扩展Hero
类时必须混合特定的特性(Lawful
/LNeutral
/Chaotic
和Good
/Neutral
/Evil
)。并且我想找到其他限制/约束客户端代码的可能性。