DEV Community

Cover image for Build a Fluent Interface in Java in Less Than 5 Minutes

Build a Fluent Interface in Java in Less Than 5 Minutes

Andrew (he/him) on January 31, 2019

(Skip to the good part!) Building a Basic Class Building classes in Java is EASY! All you need is a class declaration inside a file wit...
Collapse
 
hpj1992 profile image
Harshit

Nice article. Great explanation on each step one by one.

While this is useful to understand what is fluent interfaces, it would be really overkill if we do this for every class we are creating. To avoid that problem, there are already many libraries which provide this builder pattern on existing java objects for free. Example: Lombok.

With just one annotation @Builder on any class would implement this fluent interface by default.

I guess you might be already aware about this, but making a note of that in article would help the reader :)

Collapse
 
awwsmm profile image
Andrew (he/him)

Thanks for reading, Harshit!

This is a good point, but I think that annotations are a bit of an advanced concept -- they'd be a good topic for an article by themselves!

Collapse
 
vsilaev profile image
Valery Silaev

With a good IDE "fluent setters" can be created even faster ))
Please see doubleh.ie/index.php/2016/08/25/fl...

All you have to do is to generate getters/setter automatically by fields and then alter all of them with multi-cursor capability.

I bet it would be even faster than placing Lombok annotations ))