#include <iostream>
#include <memory>
#include <string>
class Color {
public:
virtual ~Color() = default;
virtual std::string fill() const = 0;
};
class Red : public Color {
public:
std::string fill() const override {
return "red";
}
};
class Blue : public Color {
public:
std::string fill() const override {
return "blue";
}
};
class Shape {
protected:
std::shared_ptr<Color> color_;
public:
explicit Shape(std::shared_ptr<Color> color) : color_(std::move(color)) {}
virtual ~Shape() = default;
virtual void draw() const = 0;
};
class Circle : public Shape {
public:
explicit Circle(std::shared_ptr<Color> color) : Shape(std::move(color)) {}
void draw() const override {
std::cout << "Drawing a " << color_->fill() << " circle" << std::endl;
}
};
class Rectangle : public Shape {
public:
explicit Rectangle(std::shared_ptr<Color> color) : Shape(std::move(color)) {}
void draw() const override {
std::cout << "Drawing a " << color_->fill() << " rectangle" << std::endl;
}
};
int main() {
auto red = std::make_shared<Red>();
auto blue = std::make_shared<Blue>();
Circle redCircle(red);
Rectangle blueRectangle(blue);
Circle blueCircle(blue);
Rectangle redRectangle(red);
redCircle.draw();
blueRectangle.draw();
blueCircle.draw();
redRectangle.draw();
return 0;
}