Hi All,
Usually in factory method we need to check the existance of object based on given argument and then
need to return the object and due to this we need to have multiple if and else statement and while adding one more type then again one more else block with comparision block need to be added there. can anybody let me know how to achieve same without adding if-, else block or switch statement and even i needn't to compile the code.
Circle* Circle::create_instance(string name)
{
if(name == "BlueCircle")
{
return new BlueCircle;
}
else if(name == "GreenCircle")
{
return new GreenCircle;
}
// Here in this blcok without adding anything , i should be able to support new object i.e.RedCircle and there shouldn't be any compilation effort for the same.
return NULL;
}