- A separate component for building object
- Either give builder a constructor or return it via a static function
- To make a builder fluent return this in Java or *this in C++
- Different facets of an object can be built with different builders
working in tandem via a base class
Motivation:
- When piecewise object construction is complicated,
provide an API to do it succinctly.
General builder
- A modeling class for modeling a realistic object
- A separate class (builder) to create and manage the objects
Fluent Builder
- Fluent interface allow these kind of function call: Object.FunctionA().FunctionB()
- To make this happened, simply return **this
- The modeling class can have a build function that return a builder
- To force use of builder
- Make constructor of modeling class private
- Make builder class friend of modeling class
Groovy-Style Builder
Builder Facets
- Builder Facets splits the scope of the builder into a smaller aspect. For example:
- Instead of only one builder class for modeling class Person
- We can have PersonJobBuilder, PersonAddressBuilder together with
PersonBuilder