QtDesignPatterns/flyweightpattern/interface.h

43 lines
809 B
C
Raw Normal View History

2024-02-06 17:21:37 +08:00
#include <string>
#include <iostream>
using namespace std;
class Shape
{
public:
Shape(){}
virtual ~Shape(){}
virtual void draw() = 0;
};
class Circle : public Shape
{
public:
Circle(string color) : color(color){}
void setX(int x)
{
this->x = x;
cout << "set x success" << endl;
}
void setY(int y)
{
this->y = y;
cout << "set y success" << endl;
}
void setRadius(int radius)
{
this->radius = radius;
cout << "set radius success" << endl;
}
void draw()
{
cout << "draw Circle [color: " + color + ", x: " + std::to_string(x) + ", y: " + std::to_string(y) + ", radius: " + std::to_string(radius) + "]" << endl << endl;
}
private:
int x;
int y;
int radius;
string color;
};