【发布时间】:2012-02-25 02:55:25
【问题描述】:
我想构建一些 scala 类来建模 RDF。我有类和属性。这些属性混合在类中,并且可以使用properties hashmap,因为它们的自身类型。
随着类获得更多属性,我不得不使用很多 mixin(50+),我想知道这是否仍然是一个很好的解决方案性能明智?
trait Property
trait Properties {
val properties =
new scala.collection.mutable.HashMap[String, Property]
}
abstract class AbstractClass extends Properties
trait Property1 {
this: AbstractClass =>
def getProperty1 = properties.get("property1")
}
trait Property100 {
this: AbstractClass =>
def getProperty100 = properties.get("property100")
}
class Class1 extends AbstractClass
with Property1 with Property100
【问题讨论】: