-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilder Pattern1
More file actions
52 lines (40 loc) · 1.06 KB
/
Copy pathBuilder Pattern1
File metadata and controls
52 lines (40 loc) · 1.06 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
package burger;
public class Burger {
private final String size;
private final boolean chicken;
private final boolean mutton;
private Burger(BurgerBuilder builder) {
this.size = builder.size;
this.chicken = builder.chicken;
this.mutton = builder.mutton;
}
// getters for all fields
public String getSize() {
return size;
}
public boolean isChicken() {
return chicken;
}
public boolean isMutton() {
return mutton;
}
public static class BurgerBuilder {
private final String size;
private boolean chicken;
private boolean mutton;
public BurgerBuilder(String size) {
this.size = size;
}
public BurgerBuilder chicken(boolean chicken) {
this.chicken = chicken;
return this;
}
public BurgerBuilder mutton(boolean mutton) {
this.mutton = mutton;
return this;
}
public Burger build() {
return new Burger(this);
}
}
}