Two questions on the pattern, I could not figure it out myself:

  1. Why is the inner Builder class declared public ?
  2. Why is the inner Builder class declared static ?
  • For what principle nested static classes are needed: so that you can call Foo.Builder . - Nofate
  • @Nofate Are there other reasons besides calling without creating an object? And does he have to be public? - Tariel
  • one
    No, but this is pretty good reason. In general, no one bothers you to make the builder in an independent class. Bilder he from this will not stop. - Nofate
  • @Tariel, in an amicable way, the question lacks the code of the implementation you are talking about. Builder can be implemented substantially differently;) - Dmitriy Simushev
  • what language ? What are you talking about here, absolutely not clear? Where is the sample code? - spectre_it

1 answer 1

  1. The access modifier is not directly related to the pattern architecture, but reflects the standard object access policy. You can not declare.
  2. The static parameter is needed to call a class without creating an external object, like Class.Builder ().
  • @Dmitriy Simushev This question is based on the second example of a Java pattern implementation from a wiki. All code is there, it makes no sense to duplicate here. - Tariel