QtDesignPatterns/decoratorpattern/second_interface.h

34 lines
538 B
C
Raw Permalink Normal View History

2024-02-06 17:21:37 +08:00
#include "first_interface.h"
class ShapeDecorator
{
public:
ShapeDecorator(Shape *shape)
{
this->shape = shape;
}
virtual ~ShapeDecorator(){}
virtual void draw()
{
shape->draw();
}
protected:
Shape *shape;
};
class RedShapeDecorator: public ShapeDecorator
{
public:
RedShapeDecorator(Shape *shape) : ShapeDecorator(shape){}
void setRedBorder()
{
cout << "Border color: Red" << endl;
}
void draw()
{
shape->draw();
setRedBorder();
}
};