Builder Pattern
Overview
Separate the construction of a complex object from its representation so that the same
construction process can create different representations.
Participants
- specifies an abstract interface for creating parts of a Product object.
- constructs and assembles parts of the product by implementing the Builder interface.
- defines and keeps track of the representation it creates.
- provides an interface for retrieving the product.
- constructs an object using the Builder interface.
- represents the complex object under construction. ConcreteBuilder builds the
product's internal representation and defines the process by which it's assembled.
- includes classes that define the constituent parts, including interfaces for
assembling the parts into the final results.
- the client is the object that creates and uses the Director to get the Product
Parameters
- name of the construct method in the Director, used by the Client to build the Product.
-
when selected, will create special JavaDoc links in the code between pattern participants, describing
their relationships.
Applicability
Use the Builder pattern when
- the algorithm for creating a complex object should be independent of the parts that
make up the object and how they are assembled.
- the construction process must allow different representations for the object that's
constructed.