Builder


This is a Design Pattern that allows you to build complex objects step by step. It allows different representations of an object to be produced using the same code.

It is therefore necessary to extract the construction into a separate class and declare methods for each step (buildWalls, buildDoor, etc...). To create an object, a series of methods are executed.

You don't even have to call all the steps, depending on what you want to do you can call only some of them.

We can also create a Director, which is a class that decides the order in which we create our object.

We first create an abstract Builder, which we then break down into several concrete Builders. Builders are not obliged to return products following the same interface.

You must define all the creation methods in the abstract Builder, and remember to add a method to retrieve the result.

Applicability

META

Status:: #wiki/notes/mature
Plantations:: Creational Patterns - 20230221095426
References:: Dive Into Design Patterns