Builder Design Pattern
Created: August 2nd, 2024
The Builder pattern is a creational design pattern that allows for the step-by-step construction of complex objects. It separates the construction of an object from its representation, which enables the same construction process to create different representations of the same object. The pattern consists of a Builder Interface, a Product class, one or more Concrete Builder classes, and optionally, one or more Director classes. The Concrete Builder classes implement the Builder Interface, which contains all the methods to create different parts of the complex Product object. The Director classes, if used, employ these methods in a step-by-step manner to construct the final representation of a complex Product object variant. This approach, where Director classes construct a complex object in a step-by-step manner, results in the construction of an object being separate from its representation. This is in contrast to a constructor method of a class using passed-in parameters to initialize an object's initial state; in such a scenario, there is no separation between the class that constructs the object and the object itself.