September 2019
Intermediate to advanced
816 pages
18h 47m
English
When a class (immutable or mutable) has too many fields, it requires a constructor with many arguments. When some of those fields are required and others are optional, this class will need several constructors to cover all the possible combinations. This becomes cumbersome for the developer and for the user of the class. This is where the Builder pattern comes to the rescue.
According to the Gang of Four (GoF)—the Builder pattern separates the construction of a complex object from its representation so that the same construction process can create different representations.
The Builder pattern can be implemented as a separate class or as an inner static class. Let's focus on the second ...