forked from mrn3088/patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz4-builder.java
More file actions
84 lines (66 loc) · 1.48 KB
/
quiz4-builder.java
File metadata and controls
84 lines (66 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
72
73
74
75
76
77
78
79
80
81
82
83
84
interface ISensor {
}
interface ICPU {
}
interface ILens {
}
class DSensor implements ISensor {
}
class DCPU implements ICPU {
}
class PLens implements ILens {
PLens(int size) {
}
}
class ZLens implements ILens {
ZLens(int a, int b) {
}
}
class Camera {
ISensor s;
ICPU c;
ILens l;
// Camera(ISensor si, ICPU ci, ILens li) {
// s = (si != null) ? si : new DSensor();
// c = (ci != null) ? ci : new DCPU();
// l = (li != null) ? li : new PLens(50);
// }
Camera(ISensor si, ICPU ci, ILens li) {
this.s = si;
this.c = ci;
this.l = li;
}
// ... Camera methods ...
}
class CameraBuilder {
Camera camera;
ISensor s;
ICPU c;
ILens l;
CameraBuilder useSensor(ISensor si) {
s = si == null ? new DSensor() : si;
return this;
}
CameraBuilder useCPU(ICPU ci) {
c = ci == null ? new DCPU() : ci;
return this;
}
CameraBuilder useLen(ILens li) {
l = li == null ? new PLens(50) : li;
return this;
}
Camera build() {
return new Camera(s, c, l);
}
Camera buildDefault() {
return this.useCPU(null).useLen(null).useLen(null).build();
}
}
class CameraStore {
Camera cam;
CameraStore() {
// cam = new Camera(null, null, new ZLens(24, 70)); // ß update this, too
cam = new CameraBuilder().useCPU(null).useLen(null).useLen(new ZLens(24, 70)).build();
}
// ... CameraStore methods ...
}