【发布时间】:2012-03-13 18:44:44
【问题描述】:
我有一个回调函数,叫做
MyCallBack(int type)
我有 3 个类 B、C 和 D 从 A 派生,具有通用方法名称 目前我的代码是这样的
MyCallBack(int type){
if(type == 1 ){
B b;
b.perform();
}else if(type==2) {
C c;
c.perform();
}else if(type ==3){
D d;
d.perform();
}
有没有办法可以减少这段代码,比如
MyCallBack(int type){
Common object(type);
object.perform();
}
【问题讨论】:
标签: c++ design-patterns inheritance