Hacker News new | ask | show | jobs
by culturedsystems 1560 days ago
I agree there's not much point using this kind of simple builder if you have named function parameters, but the GoF builder pattern has a couple of additional features which can still be useful. In the GoF examples the construction process is more complicated (maybe the order in which construction steps take place is significant, and maybe parts of the construction might be conditional), and the same construction algorithm can be used to produce different types of object. If I remember correctly, the main example in the GoF book is a builder for creating documents by adding a title, subtitle, paragraphs, etc, and the document being constructed might be a UI representation, an RTF file, HTML, etc.
1 comments

> maybe the order in which construction steps take place is significant

That is just horrible...

> maybe parts of the construction might be conditional

No builder pattern needed for that, just use optional arguments and/or an option/nullable type.