-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBridgePattern.cpp
More file actions
71 lines (64 loc) · 1.48 KB
/
BridgePattern.cpp
File metadata and controls
71 lines (64 loc) · 1.48 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
//Bridge Pattern
#include<iostream>
class Abstraction {
public:
virtual void Operation() = 0;
virtual ~Abstraction() {}
protected:
Abstraction() {}
};
class RefinedAbstractionA:public Abstraction {
public:
RefinedAbstractionA(AbstractImplement* imp) {
this->pImp = imp;
}
~RefinedAbstractionA() {
delete this->pImp;
this->pImp = nullptr;
}
void Operation() {
std::cout << "RefinedAbstractionA::operator" << std::endl;
this->pImp->Operator();
}
private:
AbstractImplement* pImp;
};
class RefinedAbstractionB :public Abstraction{
public:
RefinedAbstractionB(AbstractImplement* imp) {
this->pImp = imp;
}
void Operation() {
std::cout << "RefinedAbstractionB::operation" << std::endl;
this->pImp->Operator();
}
~RefinedAbstractionB() {
delete this->pImp;
this->pImp = nullptr;
}
private:
AbstractImplement* pImp;
};
class AbstractImplement {
public:
virtual void Operator() = 0;
virtual ~AbstractImplement() {}
protected:
AbstractImplement() {}
};
class ConcreteAbstractImplementA :public AbstractImplement {
public:
ConcreteAbstractImplementA() {}
~ConcreteAbstractImplementA() {}
void Operator() {
std::cout << "ConcreteAbstractImplementA::operator" << std::endl;
}
};
class ConcreteAbstractImplementB :public AbstractImplement {
public:
ConcreteAbstractImplementB() {}
~ConcreteAbstractImplementB(){}
void Operator() {
std::cout << "ConcreteAbstractImplementB::operator" << std::endl;
}
};