Skip to content

Commit 2454cd5

Browse files
committed
Pattern builder files
1 parent a6f4c4e commit 2454cd5

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

com/builder/Computer.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//Important the computer class
2+
3+
import com.builder.Computer;
4+
5+
6+
public class Computer{
7+
8+
//required params.
9+
private String ram;
10+
11+
private String hdd;
12+
13+
//optionals params
14+
private boolean isGraphicsCardEnable;
15+
private boolean isBluetoothEnabled;
16+
17+
public String getRam(){
18+
return this.ram;
19+
}
20+
21+
public String getHdd(){
22+
return this.hdd;
23+
}
24+
25+
26+
public boolean isGraphicsCardEnable(){
27+
return isGraphicsCardEnable;
28+
}
29+
30+
public boolean isBluetoothEnabled(){
31+
return isBluetoothEnabled;
32+
}
33+
34+
// Note the private visibility of the constructor, and the builder variable type.
35+
36+
private Computer(ComputerBuilder builder){
37+
38+
this.ram = com.builder;
39+
this.hdd = com.builder;
40+
41+
this.isGraphicsCardEnable = com.isGraphicsCardEnable;
42+
this.isBluetoothEnabled = com.isBluetoothEnabled;
43+
}
44+
45+
46+
//the builder inner class
47+
48+
public static class ComputerBuilder{
49+
//required params.
50+
private String ram;
51+
52+
private String hdd;
53+
54+
//optionals params
55+
private boolean isGraphicsCardEnable;
56+
private boolean isBluetoothEnabled;
57+
58+
59+
public ComputerBuilder(String hdd, String ram){
60+
this.ram = ram;
61+
this.hdd = hdd;
62+
}
63+
64+
public ComputerBuilder setGraphicsCardEnabled(boolean val){
65+
this.isGraphicsCardEnable = val;
66+
return this;
67+
}
68+
69+
public ComputerBuilder setBluetoothEnabled(boolean val){
70+
this.isBluetoothEnabled = val;
71+
72+
return this;
73+
}
74+
75+
// The build function.
76+
public Computer build(){
77+
return new Computer(this);
78+
}
79+
}
80+
81+
}

0 commit comments

Comments
 (0)