0

Everything I'm able to find concerning the builder pattern only mentions reducing the number of parameters to a constructor. But if that is all that is needed, why not just create a basic data structure to hold the parameters and pass that?

What is the purpose of a series of methods that essentially does the same thing as setting some variables of a parameter object?

4
  • Say you have a method with 15 parameters, so you create a parameter object to pass with 15 properties. Then, though, you have set all 15 properties on the parameter object, and you would want to use a constructor for that so you don't miss any. So now your parameter object has a constructor with 15 parameters.. Commented May 19, 2021 at 14:21
  • A builder is also very easily extensible Commented May 19, 2021 at 14:23
  • Also builder can build different types (in same hierarchy) based on different parameters - constructor can't. Commented May 19, 2021 at 14:29
  • The SE page on the builder pattern is useful Commented May 19, 2021 at 14:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.