Introducing the Builder Pattern
The Builder Pattern is part of the group of Creational Patterns and provides us a way to create objects that require a lot of configuration before they reach the point where they can be used. The Builder Pattern is often used for objects that accept many optional parameters in order to define their operation. Another matching case is for the creation of objects where their configuration needs to be done in several steps or in a specific order.
The common paradigm for the Builder Pattern according to Computer Science is that there is a Builder Object that provides one or more setter methods (setA(...)
, setB(...)
) and a single generation method that constructs and returns the newly created result object (getResult()
).
This pattern has two important concepts. The first one is that the Builder Object exposes a number of methods as a way to configure the different parts of the object that is under construction. During the configuration phase, the Builder Object preserves...