Small Note : Yes the properties might be a repeat but they have advantages
Details below : If you look at the details here.
Pizza pizza = new Pizza(12);
pizza.setCheese(true);
pizza.setPepperoni(true);
pizza.setBacon(true);
The problem here is that because the object is created over several calls it may be in an inconsistent state partway through its construction. This also requires a lot of extra effort to ensure thread safety.
The better alternative is to use the Builder Pattern.
Notice below method in Builder and respective constructor or parent Pizza class - full code in link here
public static class Builder {
public Pizza build() { // Notice this method
return new Pizza(this);
}
}
private Pizza(Builder builder) { // Notice this Constructor
size = builder.size;
cheese = builder.cheese;
pepperoni = builder.pepperoni;
bacon = builder.bacon;
}