One common example of the Builder design pattern is the creation of a pizza. The pizza has various ingredients such as crust, meats, sauces, and toppings that can be added in different combinations to create a unique pizza. The Builder design pattern allows a developer to specify the steps for creating a pizza, while leaving the actual construction to a separate object.
In this example, the pizza would be the complex object that is being constructed, and the Builder would be the object responsible for creating it. The Builder would have methods for adding the various ingredients to the pizza, such as `setCrust(_ crust: Pizza.Crust)`, `func addMeat(_ meat: Pizza.Meats)`, and `func removeMeat(_ meat: Pizza.Meats)`, `func addSauce(_ sauce: Pizza.Sauces)`, etc.
To use the PizzaBuilder, a client can create a new PizzaBuilder object and then use its methods to customize the pizza being constructed. The PizzaBuilder methods return the PizzaBuilder object itself, allowing for method chaining, which makes it easy to specify the desired characteristics of the pizza in a single line of code. Once the pizza has been customized, the `build()` method can be called to return the completed Pizza object.
To create a veggie pizza, we would create an instance of the PizzaBuilder and pass it to the Director. The Director would then call the appropriate static method to add the necessary ingredients in the correct order.
Here is an example: