QtDesignPatterns/factorypattern/shapefactory.h

27 lines
481 B
C
Raw Permalink Normal View History

2024-02-06 17:21:37 +08:00
#include "interface.h"
class ShapeFactory
{
public:
ShapeFactory(){}
Shape* getShape(string type)
{
if (type.compare("Circle") == 0)
{
return new Circle();
}
else if (type.compare("Square") == 0)
{
return new Square();
}
else if (type.compare("Rectangle") == 0)
{
return new Rectangle();
}
else
{
return nullptr;
}
}
};