类工厂写成下面这样,缺点如下:
1.会依赖于具体类的头文件、lib库;
2.以后添加新的具体类,还得修改类工厂,包含新类的头文件、lib库
Object* FactoryCreat(const string& className)
{
if (className == "ClassA")
return new ClassA;
else if (className == "ClassB")
return new ClassB;
else if(className == "ClassC")
return new ClassC;
else if(className == "ClassD")
return new ClassD;
else if(className == "ClassE")
return new ClassE;
...
--
FROM 124.193.98.*