Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 6: Builder > When Would You Use the Builder Pattern?

When Would You Use the Builder Pattern?

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.

  

Start a Free Trial