Session
Fluent Setters: breaking the convention
What if we return "this" object in setter methods instead of void? This can drastically change the coding style.
Instead of plain code using a lot of local variables we can write nested expressions like (see presentation slides).
A lot of modern frameworks and tools support it correctly: spring and spring-boot, jOOQ, jackson, Hibernate, Mapstruct, IntelliJ IDEA, Lombok, Kotlin language, Groovy language, etc.
What about the standard? Surprisingly, it does not specify explicitly the return type for setters (only naming convention and single argument).
But default implementation java.beans.Introspector expects void 🫠. For this reason it would not work well e.g. in traditional JavaEE stack.
This approach can be a good option for new projects. Also it can be adopted iteratively to existing.
In the presentation it's also compared to more traditional record classes and Lombok Builder.
Also there will be an inheritance problem (return this of super type), which is also explained.
This is an original research and fresh look to a basic pattern.

Sergei Chernov
Miro, Staff Software engineer
Amsterdam, The Netherlands
Links
Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.
Jump to top