QtDesignPatterns/flyweightpattern/shapefactory.h

24 lines
508 B
C
Raw Normal View History

2024-02-06 17:21:37 +08:00
#include "interface.h"
#include <map>
class ShapeFactory
{
public:
std::map<string, Shape*> map;
auto getCircle(string color)->Shape*
{
auto iter = map.find(color);
if (iter != map.end())
{
return iter->second;
}
else
{
Shape *circle = new Circle(color);
map.insert(std::make_pair(color, circle));
cout << "Creating circle of color : " + color << endl;
return circle;
}
}
};