-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactoryAdapter.cpp
More file actions
159 lines (128 loc) · 2.7 KB
/
FactoryAdapter.cpp
File metadata and controls
159 lines (128 loc) · 2.7 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// Factory Adapter.
//
//
#include <iostream>
using namespace std;
class Bone{
public:
virtual void draw()=0;
Bone(){
boneId = boneTotal++;
}
protected:
int boneId;
static int boneTotal;
};
int Bone::boneTotal=0;
class Tibia:public Bone{
public:
void draw(){
cout << "Tibia bone" << endl;
}
};
class fibia:public Bone{
public:
void draw(){
cout <<" fibia bone " << endl;
}
};
class femur:public Bone {
public:
void draw(){
cout << " femur draw " << endl;
}
};
class Radius:public Bone{
public:
void draw(){
cout << "Radius bone" << endl;
}
};
class Humerus:public Bone {
public:
void draw(){
cout << "Humerus bone " << endl;
}
};
class Ulna:public Bone{
public:
void draw(){
cout << "Ulna bone " << endl;
}
};
class FactoryForArms{
public:
virtual Bone* createArmBigBone()=0;
virtual Bone* createArmSmallBone1()=0;
virtual Bone* createArmSmallBone2()=0;
};
class FactoryForLegs{
public:
virtual Bone* createLegBigBone()=0;
virtual Bone* createLegSmallBone1()=0;
virtual Bone* createLegSmallBone2()=0;
};
class ArmFactory : public FactoryForArms {
public:
Bone* createArmBigBone(){
return new Humerus;
}
Bone* createArmSmallBone1(){
return new Radius;
}
Bone* createArmSmallBone2(){
return new Ulna;
}
};
class LegFactory : public FactoryForLegs {
public:
Bone* createLegBigBone(){
return new femur;
}
Bone* createLegSmallBone1(){
return new Tibia;
}
Bone* createLegSmallBone2(){
return new fibia;
}
};
class Arm {
enum{HUMERUS=0,RADIUS=1,ULNA=2};
public:
Arm(){
FactoryForArms* BoneFactory = new ArmFactory;
ArmBones[HUMERUS] = BoneFactory->createArmBigBone();
ArmBones[HUMERUS]->draw();
ArmBones[RADIUS] = BoneFactory->createArmSmallBone1();
ArmBones[RADIUS]->draw();
ArmBones[ULNA] = BoneFactory->createArmSmallBone2();
ArmBones[ULNA]->draw();
}
protected:
int size;
Bone* ArmBones[3];
};
class Leg {
enum{FEMUR=0,TIBIA=1,FIBIA=2};
public:
Leg(){
FactoryForLegs* BoneFactory = new LegFactory;
LegBones[FEMUR] = BoneFactory->createLegBigBone();
LegBones[FEMUR]->draw();
LegBones[TIBIA] = BoneFactory->createLegSmallBone1();
LegBones[TIBIA]->draw();
LegBones[FIBIA] = BoneFactory->createLegSmallBone2();
LegBones[FIBIA]->draw();
}
protected:
int size;
Bone* LegBones[3];
};
int main (int argc, const char * argv[])
{
Arm rightArm;
Arm leftArm;
Leg rightLeg;
return 0;
}