Jonathan Gros-Dubois
1 min readNov 6, 2022

--

Yes. I can see what problems it solves but it's not the most efficient way to do so as it also introduces a new problem; it can be misused to make code less readable.

The same core problems can be solved by having a single factory 'create' method/function with optional parameters; you can support named parameters to avoid having to pass null arguments. The benefit of this over the builder pattern with currying is that the factory method forces the creation of the instance to happen in one place. With currying, it's possible to partially instantiate in one file, then have a different file complete the instantiation; in my experience, this is an anti-pattern which makes the code difficult to read and maintain — It encourages developers to violate separation of concerns between different components (which is one of the most important principles). Instantiating a particular instance is a single concern; it doesn’t make sense to spread it out over multiple files… Even if you’re dealing with scenarios such as a user filling out a multi-page form, you can simply buffer all the necessary data into a map and/or array until the final stage when you actually need to instantiate.

I can't say that I hate the builder pattern since it's possible to use it in the safe way. My main issue with it is that whatever flexibility it provides over simpler approaches such as using a factory method (with optional, named arguments) is undesirable and it can encourage overly complex software design/architecture which is more difficult to maintain.

--

--

No responses yet