F
firegun9
Hello,
I have a design problme in my project.
The abstract is below:
class Container{
Base* p_base;
void create_child(int type, argu1, argu2...)
{
switch(type){
case 0:
p_base = new Child_1(argu1, argu2);
break;
case 1:
p_base = new Child_2(argu1, argu2, argu3);
break;
...
}
}
There is a pointer of type "Base" in the class "Container", and I hope
the pointer can be used in any kind of child class derived from "Base"
class.
The switch-case above is the solution I could come up with.
But the disadvantage is if there is a new type child in the future, I
have to come back to add one more case in create_child().
Anyone has a better idea?
I have a design problme in my project.
The abstract is below:
class Container{
Base* p_base;
void create_child(int type, argu1, argu2...)
{
switch(type){
case 0:
p_base = new Child_1(argu1, argu2);
break;
case 1:
p_base = new Child_2(argu1, argu2, argu3);
break;
...
}
}
There is a pointer of type "Base" in the class "Container", and I hope
the pointer can be used in any kind of child class derived from "Base"
class.
The switch-case above is the solution I could come up with.
But the disadvantage is if there is a new type child in the future, I
have to come back to add one more case in create_child().
Anyone has a better idea?