我正在使用新版本tcl9.0中的configure,它可以工作,但我有一个问题: 如何使类既可配置又抽象? 我尝试这样做:
oo::abstract create Simulator {
mixin oo::configurable
property Name -set {
error "Not implemented"
}
variable Name
}
但是它会引发属性未知的错误。 预先感谢您!
你需要做:
oo::configurable create Simulator {
self mixin -append oo::abstract
property Name -set {
error "Not implemented"
}
variable Name
}
这是因为
oo::configurable
做了一些狡猾的事情,将 property
添加到配置命令集中,这意味着需要在调用 oo::define
之前对其进行断言(是的,类只是在其构造函数中将其传递出去);在通话期间添加它意味着只有下一次oo::define
被调用才会受到影响。
相比之下,
oo::singleton
非常简单;它目前只是使 create
和 new
直接成为相关类(而不是其子类)上的非导出方法,并且不会更改定义命令上下文。这使得它足够简单,可以作为 mixin 工作。我们使用self mixin -append
是因为我们可能向类中添加其他mixin,并且想要影响类对象本身。