DEV Community

Discussion on: When Builder is anti-pattern

Collapse
 
aleksikauppila profile image
Aleksi Kauppila

Builders are horrible. I've used them mainly in SQL query builder context, but also seen the things you described in the wild.

It's definitely a clear indication of design problems when some builders start popping in the code base. If you're objects are so hard to create that you need some builder class to create those, you need to take a look at the classes you're creating and fix the problem there.

Factories using reasonable parameter objects are easier to work with and also easier to test even when the mistake of too big classes has already been made.

Collapse
 
aminmansuri profile image
hidden_dude

Yeah, back in the day when we'd manually build our own SQL a builder pattern was very useful. I suppose other use cases could be creating other text formats. Or the obvious application of a builder is for Wizards. A wizard is a set of steps and the builder is the most natural way to feed those steps until you're ready to run.