B
B
Bamp2020-03-31 16:05:14
PHP
Bamp, 2020-03-31 16:05:14

Why use the Builder pattern when you can pass an array to the constructor?

I read on resources that one of the reasons for using the Builder pattern is to create an object with a large number of parameters. But why not just use an array passed to the constructor for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2020-03-31
@ThunderCat

Firstly, hinting, without looking into an absurdly long array, you can determine which fields are there by IDE auto-hinting, and not type them manually.
Secondly - OOP goodies, such as inheritance, for example, create a base object with most of the fields you need everywhere, and if necessary, expand and customize.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question