@@ -28,6 +28,14 @@ class Machine {
28
28
private Machine () {
29
29
}
30
30
31
+ // actual class constructor that takes the Builder object
32
+ private Machine (final MachineBuilder machineBuilder ) {
33
+ this .HDD = machineBuilder .HDD ;
34
+ this .RAM = machineBuilder .RAM ;
35
+ this .GPU = machineBuilder .GPU ;
36
+ this .isBluetoothEnabled = machineBuilder .isBluetoothEnabled ;
37
+ }
38
+
31
39
public String getRAM () {
32
40
return RAM ;
33
41
}
@@ -44,36 +52,18 @@ public boolean isBluetoothEnabled() {
44
52
return isBluetoothEnabled ;
45
53
}
46
54
47
- @ Override
48
- public String toString () {
49
- return "Machine{" +
50
- "RAM='" + RAM + '\'' +
51
- ", HDD='" + HDD + '\'' +
52
- ", GPU='" + GPU + '\'' +
53
- ", isBluetoothEnabled=" + isBluetoothEnabled +
54
- '}' ;
55
- }
56
-
57
- // actual class constructor that takes the Builder object
58
- private Machine (MachineBuilder machineBuilder ) {
59
- this .HDD = machineBuilder .HDD ;
60
- this .RAM = machineBuilder .RAM ;
61
- this .GPU = machineBuilder .GPU ;
62
- this .isBluetoothEnabled = machineBuilder .isBluetoothEnabled ;
63
- }
64
-
65
55
//Public Static Builder Class
66
56
public static class MachineBuilder {
67
57
// Required Parameters
68
- private String RAM ;
69
- private String HDD ;
58
+ private final String RAM ;
59
+ private final String HDD ;
70
60
71
61
// Optional Parameter
72
62
private String GPU ;
73
63
private boolean isBluetoothEnabled ;
74
64
75
65
// constructor for Required Parameters
76
- public MachineBuilder (String RAM , String HDD ) {
66
+ public MachineBuilder (final String RAM , final String HDD ) {
77
67
this .HDD = HDD ;
78
68
this .RAM = RAM ;
79
69
}
@@ -90,8 +80,18 @@ public MachineBuilder setBluetooth(boolean isBluetoothEnabled) {
90
80
}
91
81
92
82
// build method which returns actual Object
93
- public Machine build () {
83
+ protected Machine build () {
94
84
return new Machine (this );
95
85
}
96
86
}
87
+
88
+ @ Override
89
+ public String toString () {
90
+ return "Machine{" +
91
+ "RAM='" + RAM + '\'' +
92
+ ", HDD='" + HDD + '\'' +
93
+ ", GPU='" + GPU + '\'' +
94
+ ", isBluetoothEnabled=" + isBluetoothEnabled +
95
+ '}' ;
96
+ }
97
97
}
0 commit comments