Builder
Last updated
Last updated
Builder is a creational design pattern that lets you construct complex objects step by step.
The pattern allows you to produce different types and representations of an object using the same construction code.
The Builder design pattern is a creational pattern used to construct complex objects step by step.
It separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
In this example:
Pizza
is the product class representing the complex object we want to build.
PizzaBuilder
is the builder class that helps in constructing the Pizza
object step by step.
The builder class allows setting different attributes of the Pizza
object and then finally builds the Pizza
object with the build()
method.
This pattern allows for flexibility in constructing complex objects, as you can add or change the construction process without affecting the client code.