Pessoal, vi o exemplo no link: http://stackoverflow.com/questions/328496/when-would-you-use-the-builder-pattern
e fiquei com a seguinte dúvida:
[code]public class Pizza {
private int size;
private boolean cheese;
private boolean pepperoni;
private boolean bacon;
public static class Builder {
//required
private final int size;
//optional
private boolean cheese = false;
private boolean pepperoni = false;
private boolean bacon = false;
public Builder(int size) {
this.size = size;
}
public Builder cheese(boolean value) {
cheese = value;
return this;
}
public Builder pepperoni(boolean value) {
pepperoni = value;
return this;
}
public Builder bacon(boolean value) {
bacon = value;
return this;
}
public Pizza build() {
return new Pizza(this);
}
}
private Pizza(Builder builder) {
size = builder.size;
cheese = builder.cheese;
pepperoni = builder.pepperoni;
bacon = builder.bacon;
}
}
[/code]
No retorno tenho seguinte: Pizza pizza = new Pizza.Builder(12).cheese(true).pepperoni(true).bacon(true).build();
Só que, se as variáveis size,cheese,pepperoni,bacon são do tipo private. Como eu posso acessá-las?;