The builder is a type of creational pattern that helps in building complex objects as It provides a flexible and step-by-step approach towards making these objects. It also keeps the representation and process of creation shielded.
- so when object construction is complicated, provide an API for doing it clearly.
- Consider the example of a restaurant that has to build a pizza for its customers. The building process has various stages
When to use
You can use this design pattern when building apps that require you to create complex objects. It can help you hide the construction process of building these objects
A good example would be a DOM, where you might need to create plenty of nodes and attributes. The construction process can get quite messy if you are building a complex DOM object. In cases like these, the builder pattern can be used.
another example is the query builder which requires multiple conditions and criteria before executing the query itself