-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBridge.cpp
59 lines (46 loc) · 1.21 KB
/
Bridge.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//g++ Bridge.cpp -Wc++11-extensions -std=c++11
#include <iostream>
#include <memory>
class DrawAPI{
public:
virtual void drawCircle(int radius,int x,int y) = 0;
};
class RedCircle:public DrawAPI{
public:
void drawCircle(int radius,int x,int y){
std::cout<<"Drawing Circle[ color: red, radius: "<<radius<<", x: "<<x<<", "<<y<<"]";
}
};
class GreenCircle:public DrawAPI{
public:
void drawCircle(int radius,int x,int y){
std::cout<<"Drawing Circle[ color: green, radius: "<<radius<<", x: "<<x<<", "<<y<<"]";
}
};
class Shape{
protected:
std::shared_ptr<DrawAPI> _drawAPI;
Shape(const std::shared_ptr<DrawAPI> &drawapi){
_drawAPI = drawapi;
}
public:
virtual void draw() = 0;
};
class Circle:public Shape{
private:
int _x, _y, _radius;
public:
Circle(int x, int y, int radius, const std::shared_ptr<DrawAPI> &drawapi):Shape(drawapi) {
_x = x;
_y = y;
_radius = radius;
}
void draw(){
_drawAPI->drawCircle(_radius,_x,_y);
}
};
int main(){
std::shared_ptr<Shape> redcircle = std::make_shared<Circle>(100,100,10,std::make_shared<RedCircle>());
redcircle->draw();
return 0;
}