Repository navigation
Expand file tree
/
Copy pathStructural-BridgeDesignPattern.cpp
More file actions
132 lines (93 loc) · 2.19 KB
/
Copy pathStructural-BridgeDesignPattern.cpp
File metadata and controls
132 lines (93 loc) · 2.19 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*Bridge design pattern is used to decouple a class into two parts – abstraction and it’s implementation –
so that both can evolve in future without affecting each other. It increases the loose coupling between
class abstraction and its implementation */
#include <iostream>
#include <string>
using namespace std;
class fillColorImp
{
public:
virtual void fillColor() = 0;
};
class greenColor : public fillColorImp
{
public:
void fillColor()
{
cout<<"Its is Green color"<<endl;
}
};
class redColor : public fillColorImp
{
public:
void fillColor()
{
cout<<"Its is red color"<<endl;
}
};
class Shape {
public:
virtual void colorIt() = 0;
virtual void drawIt() = 0;
};
class bridge : public Shape
{
protected :
fillColorImp* colorObj1;
public:
bridge(fillColorImp* obj)
{
cout<<"\ninside consstructor of bridge class\n"<<endl;
colorObj1 = obj;
}
};
class squar : public bridge
{
public:
squar(fillColorImp* obj):bridge(obj) {}
void colorIt()
{
colorObj1->fillColor();
}
void drawIt()
{
cout<<"Squar drawan without color"<<endl;
}
};
class Rectangle : public bridge
{
public:
Rectangle(fillColorImp* obj):bridge(obj) {}
void colorIt()
{
colorObj1->fillColor();
}
void drawIt()
{
cout<<"Squar drawan without color"<<endl;
}
};
int main() {
Shape *shapeobj1;
fillColorImp *ObjRed = new redColor;
fillColorImp *ObjGreen = new greenColor;
//UseCase1
cout<<"\nUsecase1"<<endl;
cout<<"------------------------------------"<<endl;
shapeobj1 = new squar(ObjRed);
shapeobj1->colorIt();
shapeobj1->drawIt();
shapeobj1 = new squar(ObjGreen);
shapeobj1->colorIt();
shapeobj1->drawIt();
//UseCase1
cout<<"\nUsecase2 "<<endl;
cout<<"------------------------------------"<<endl;
shapeobj1 = new Rectangle(ObjRed);
shapeobj1->colorIt();
shapeobj1->drawIt();
shapeobj1 = new Rectangle(ObjGreen);
shapeobj1->colorIt();
shapeobj1->drawIt();
return 0;
}