If the code that wants a new instance of HttpClientBuilder
creates the object itself via a constructor, then it will forever more create exactly that type of object, and it will lock in a certain set of parameters that it passes to the constructor.
The factory method create
has more flexibility. As shown, it is returning a HttpClientBuilder
anyway. But say something changes and and the authors of HttpClientBuilder
want to, under certain circumstances, return a special new subclass of HttpClientBuilder
. With the factory method, they can do that, and none of the client code will have to change or will even know the difference. That change can't be made without changing the client code in the case where the constructor is called directly. So the factory method generally has more flexibility for future modification by the class's authors than the constructor being called directly.