-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathNyPizza.java
More file actions
31 lines (23 loc) · 744 Bytes
/
NyPizza.java
File metadata and controls
31 lines (23 loc) · 744 Bytes
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
package effectivejava.chapter2.item2.hierarchicalbuilder;
import java.util.Objects;
// Subclass with hierarchical builder (Page 15)
public class NyPizza extends Pizza {
public enum Size { SMALL, MEDIUM, LARGE }
private final Size size;
public static class Builder extends Pizza.Builder<Builder> {
private final Size size;
public Builder(Size size) {
this.size = Objects.requireNonNull(size);
}
@Override public NyPizza build() {
return new NyPizza(this);
}
}
private NyPizza(Builder builder) {
super(builder);
size = builder.size;
}
@Override public String toString() {
return "New York Pizza with " + toppings;
}
}