In builder design pattern,
is method buildpart()
a factory method? (For comparison, an abstract factory is a collection of factory methods.)
Why are they (not) factory methods? For clarification, could you also provide the definition of a factory method?
An example for buildpart()
from Design Patterns by Gamma et al is:
void StandardMazeBuilder::BuildMaze () {
_currentMaze = new Maze;
}
A factory method creates a concrete object/product, usually with the
new
keyword, and returns that object. Typicall the name of a factory method starts with prefixcreate
.The
buildpart()
method in the context of Builder Pattern may create some object, but does not return that object. From the perspective of the Director, it does not need to receive the part created by thebuildpart()
method. The Director just wants to instruct the Builder to build parts in a wanted order, and finally receive the final product.In short, due to the difference between
create
andbuild
, abuildpart()
method is not a factory method.