forked from sdmg15/Java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputer.java
More file actions
81 lines (54 loc) · 1.37 KB
/
Computer.java
File metadata and controls
81 lines (54 loc) · 1.37 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
//Important the computer class
import com.builder.Computer;
public class Computer{
//required params.
private String ram;
private String hdd;
//optionals params
private boolean isGraphicsCardEnable;
private boolean isBluetoothEnabled;
public String getRam(){
return this.ram;
}
public String getHdd(){
return this.hdd;
}
public boolean isGraphicsCardEnable(){
return isGraphicsCardEnable;
}
public boolean isBluetoothEnabled(){
return isBluetoothEnabled;
}
// Note the private visibility of the constructor, and the builder variable type.
private Computer(ComputerBuilder builder){
this.ram = com.builder;
this.hdd = com.builder;
this.isGraphicsCardEnable = com.isGraphicsCardEnable;
this.isBluetoothEnabled = com.isBluetoothEnabled;
}
//the builder inner class
public static class ComputerBuilder{
//required params.
private String ram;
private String hdd;
//optionals params
private boolean isGraphicsCardEnable;
private boolean isBluetoothEnabled;
public ComputerBuilder(String hdd, String ram){
this.ram = ram;
this.hdd = hdd;
}
public ComputerBuilder setGraphicsCardEnabled(boolean val){
this.isGraphicsCardEnable = val;
return this;
}
public ComputerBuilder setBluetoothEnabled(boolean val){
this.isBluetoothEnabled = val;
return this;
}
// The build function.
public Computer build(){
return new Computer(this);
}
}
}