Recently, I was asked in an interview to implement Builder Pattern in such a way that user cannot set a parameter B unless parameter A is set.
I suggested to pass A as a required parameter when constructing the Builder but he was not satisfied with my answer. I also suggested to throw IllegelStateException if A is not set when setting B but again he was not satisfied. Could anyone suggest how can we enforce user to set A before he sets B?
class Example{
private int A;
private int B;
public static class Builder{
}
}