问题
现有某个类型的功能模块ActSubject,其包含某些固定流程的方法mainFunc1、mainFunc2、mainFunc3等,这些流程性方法只能在和其它同类型的功能模块的共同父类ActSubjectBase中的baseFunc中调用,并且伴随一些其它的行为调用。
abstract class ActSubjectBase {
baseFunc(condition:number){
if(condition === 1){
...此处有其它行为调用
this.mainFunc1()
...此处有其它行为调用
}
if(condition === 2){
...此处有其它行为调用
this.mainFunc2()
...此处有其它行为调用
}
if(condition === 3){
...此处有其它行为调用
this.mainFunc3()
...此处有其它行为调用
}
}
abstract mainFunc1():void
abstract mainFunc2():void
abstract mainFunc3():void
...
}
class ActSubject extends ActSubjectBase {
mainFunc1(){
}
mainFunc2(){
}
mainFunc3(){
}
...
}
ActSubject和其它同类模块ActSubjectOtherXX在某个实例加载器中以统一的方式统一构造。
const ActSubjectConstructorMap = {
[subject_type_0] : ActSubject,
[subject_type_1] : ActSubjectOther1,
[subject_type_2] : ActSubjectOther2,
...
}
class ActRouter {
loadAct(subject_type){
...
return new ActSubjectConstructorMap[subject_type