No, this is not a Builder template. This is valid Java and it will compile and run. But your buildNewDrink() method, called build() or buildNewDrink() or something else, is just a simple Factory method that creates CoffeeDrink . These other methods are similar to setter methods that return themselves.
The static class of the nested Builder is required. By holding onto the instantiation of the class, it can execute validation logic to ensure that an invalid object is not created. Iโm not sure that there is an invalid state for CoffeeDrink , just as you have, but if that were the case, it would be possible with your code to create CoffeeDrink and turn it into an invalid state after it was but before it was called other methods. The Builder pattern eliminates this possibility by validating the data before creating the instance. It also eliminates the need for a constructor explosion where many constructors are required with all possible combinations of parameters to cover all possible cases.
source share