我想做一个抽象类字典来存储扩展抽象类的类,而不是实例。但我有一个问题。
myStateComputation :: IState Int String Bool
myStateComputation =
-- poor man's do notation. You could use RebindableSyntax
get >>>= \s ->
put (show s) >>>
ireturn (s > 5)
main = print $ runIState myStateComputation 3
-- ("3", False)
那么,您认为我怎么能得到这个?
我不想从AbstractClass中删除abstract修饰符,因为我需要它。
答案 0 :(得分:0)
abstract class AbstractClass{
foo(){
// do someThing
}
}
class ConcreteClass extends AbstractClass{
foo(){
super.foo()
}
}
interface ClassDicctionary {
[index:string]: new() => AbstractClass; // <---
}
let dicctionary : ClassDicctionary = { "ONE" : ConcreteClass }
new dicctionary["One"]().foo();
答案 1 :(得分:-1)
abstract class AbstractClass{
constructor( foo:string){
}
foo(){
// do someThing
}
}
class ConcreteClass extends AbstractClass{
constructor( foo:string, bar: number){
super(foo)
}
foo(){
super.foo()
}
}
interface ClassDicctionary {
[index:string]: new( ...args) => AbstractClass; // <---
}
let dicctionary : ClassDicctionary = { "ONE" : ConcreteClass }
new dicctionary["One"]().foo(); // No error but It needs some arguments