QtDesignPatterns/bridgepattern/second_interface.h

37 lines
578 B
C++

#include "first_interface.h"
class Shape
{
public:
virtual ~Shape(){}
DrawApi *getDrawApi()
{
return this->drawApi;
}
virtual void draw() = 0;
protected:
DrawApi *drawApi;
Shape(DrawApi *drawApi): drawApi(drawApi){}
};
class Circle: public Shape
{
public:
Circle(int radius, int x, int y, DrawApi *drawApi): Shape(drawApi)
{
this->x = x;
this->y = y;
this->radius = radius;
}
void draw()
{
getDrawApi()->drawCircle(radius, x, y);
}
private:
int x;
int y;
int radius;
};