Builder Pattern Flashcards
builder pattern
used to build objects. Sometimes, the objects we create can be complex, made up of several sub-objects or require an elaborate construction process. The exercise of creating complex types can be simplified by using the builder pattern. A composite or an aggregate object is what a builder generally builds.
-builder pattern advantage
a builder pattern encapsulates or hides the process of building a complex object and separates the representation of the object and its construction. The separation allows us to construct different representations using the same construction process
The class diagram consists of
Builder
Concrete Builder
Director
Product
The builder pattern might seem similar to the abstract factory pattern but one difference is that
the builder pattern creates an object step by step whereas the abstract factory pattern returns the object in one go.
Builder class
contains a method for each component that can be part of the final product. }
These methods are selectively overridden by concrete builders depending on if the builders will be including that part in the final product variant that they are responsible for building.
Director class
contains The process or algorithm required to construct the product
Skipping the Director
You may find the builder pattern being used without the director. The client can directly instantiate the builder and invoke the required methods to get a product for itself.