forked from micooz/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototypePattern.cpp
More file actions
38 lines (30 loc) · 766 Bytes
/
Copy pathPrototypePattern.cpp
File metadata and controls
38 lines (30 loc) · 766 Bytes
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
#include <iostream>
using namespace std;
// Prototype
class Prototype {
public:
virtual Prototype* Clone() = 0;
virtual ~Prototype() { }
};
class ConcretePrototype :public Prototype {
public:
ConcretePrototype() { }
ConcretePrototype(const ConcretePrototype&cp) {
cout << "ConcretePrototype copy..." << endl;
}
Prototype* Clone() {
return new ConcretePrototype(*this);
}
};
int main() {
Prototype *prototype = new ConcretePrototype();
cout << prototype << endl;
Prototype* prototype1 = prototype->Clone();
cout << prototype1 << endl;
Prototype* prototype2 = prototype->Clone();
cout << prototype2 << endl;
delete prototype;
delete prototype1;
delete prototype2;
return 0;
}