You'd naturally think about using this pattern when
You need to create a complex object that involves different parts. The algorithm for creating it should be independent of how the parts are assembled. A common example is building a composite object.
You need a construction process that constructs an object in different ways (e.g., different combinations of parts or representations).
BUILDER VS. ABSTRACT FACTORY
We discussed Abstract Factory in the last chapter. You might have realized that both the Abstract Factory and Builder patterns are similar in many ways in terms of being used for abstract object creation. However, they are very different. Builder focuses on constructing a complex object step-by-step, when a lot of times the same type of object can be constructed in different ways. On the other hand, Abstract Factory's emphasis is on creating suites of products that can be either simple or complex. A builder returns a product as a final step of a multiple-step construction process, but the product gets returned immediately from an abstract factory. The following table summarizes the main differences between the Builder and Abstract Factory ....
You are currently reading a PREVIEW of this book.
Get instant access to over
$1 million worth of books and videos.