DEV Community

Discussion on: Building Generic Payloads with the Builder Pattern in Java

Collapse
 
parthasutradhar profile image
Partha Sutradhar

Thanks Sergiy. Yes, it'll result in NPE without optional params. Let me know if we can do something to fix this?

Collapse
 
siy profile image
Sergiy Yevtushenko

There is a Fluent Builder pattern, suitable for cases when all (or majority) of parameters are required. You may find interesting this article.

Thread Thread
 
parthasutradhar profile image
Partha Sutradhar • Edited

Yes, Step Builder will force client to provide datum.

Thread Thread
 
siy profile image
Sergiy Yevtushenko

Moreover, this pattern enforces order in which fields are assigned. This is helpful in many situations, especially when changes in code are compared.