What should I do to subclass fwt::Table, with multi set to true? Any help appreciated.
using fwt
class MyTable: Table {
// Bool multi := true // ERROR: Cannot override non-virtual slot
new make(TableModel tm): super() {
// multi = true // ERROR: Cannot set const field
model = tm
}
}
class MyTableModel: TableModel {
new make() {}
override Int numRows() { 1 }
override Str text(Int row, Int col) { "foo" }
}
class TableTest {
Void main() {
TableModel tm := MyTableModel()
MyTable myTable := MyTable(tm)
// ...
}
}
DubheadThu 26 Mar 2009
Um, this must be the same issue discussed in "initialize const field in superclass - how to?" (topic 487). Sorry for duplication, please ignore this.
brianThu 26 Mar 2009
yeap you got it - hopefully I will start working on it-blocks next week and have a new build out in a week or two
in the meantime, the only practical solution is to to have the guy who constructor MyTable set it, or you can use a factory method on MyTable
brianFri 10 Apr 2009
How subclassing works with const classes and it-blocks is still not very clean. You don't want to pass an it-block to your parent's constructor if you are going to apply it yourself, because then it would get applied twice:
class A { new make(|This| f) { f(this) } }
class B : A { new make(|This| f) : super(f){ f(this) } }
So there has to be a contract b/w the superclass and subclass for who is in charge of applying the it-block, which in turn requires a contract about how to validate. So we might have to say you shouldn't use a const/it-block styled API if you intend to support subclasses.
For now I changed the compiler to allow a subclass to set its parent's const fields in its own constructor. But I am not going to worry about this particular problem too much right now, I want to get the overall feature rolled out so we can start playing with it.
Dubhead Thu 26 Mar 2009
What should I do to subclass fwt::Table, with
multi
set to true? Any help appreciated.Dubhead Thu 26 Mar 2009
Um, this must be the same issue discussed in "initialize const field in superclass - how to?" (topic 487). Sorry for duplication, please ignore this.
brian Thu 26 Mar 2009
yeap you got it - hopefully I will start working on it-blocks next week and have a new build out in a week or two
in the meantime, the only practical solution is to to have the guy who constructor MyTable set it, or you can use a factory method on MyTable
brian Fri 10 Apr 2009
How subclassing works with const classes and it-blocks is still not very clean. You don't want to pass an it-block to your parent's constructor if you are going to apply it yourself, because then it would get applied twice:
So there has to be a contract b/w the superclass and subclass for who is in charge of applying the it-block, which in turn requires a contract about how to validate. So we might have to say you shouldn't use a const/it-block styled API if you intend to support subclasses.
For now I changed the compiler to allow a subclass to set its parent's const fields in its own constructor. But I am not going to worry about this particular problem too much right now, I want to get the overall feature rolled out so we can start playing with it.