Builder Design Pattern

Amalakanthan R
1 min readMay 24, 2021

The Builder Design Pattern is a creational Design Pattern for creating complex objects. Builder design pattern is much helpful when a developer wants to create an object for a class which has numerous attributes. The object of the builder class is independent from the other objects.

The primary goals of Builder Design Patters are:

1) split the object creation process into its own Builder object.

2) Instead of explicitly creating the object, we simply delegate the object creation to the Builder object.

Why Builder Design Pattern?

Let’s say the object has several attributes, then all the arguments have to be passed to the Factory class from the Client code. And maintaining the order of the arguments becomes very repetitive if the majority of the arguments are of the same type.

we must transfer all of the arguments from the Client code to the factory class, but what if some of the parameters are optional?

So, how do you think as a developer you could overcome the above stated problems? Builder pattern would be the ideal solution that we could derive, to construct an immutable class which has large number of attributes.

We’ve created a Person class in which the name is required but whereas the age and phone number are optional. We also created a builder class called PersonBuilder, which creates Person objects. Furthermore, when constructing an object, we are not obligated to pass the parameters which are optional. As a result, the builder design pattern has solved all the problems listed above.

--

--