Tuesday, January 10, 2012

Where to use a Builder pattern

The big difference between Builder pattern and Abstract factory pattern is that the builder pattern doesnt immediately return a complete product in a single call.

The Director uses various building blocks of the builder and builds the product. The director is responsible to call the builds of the components.

A good doc on this can be found in the below link.

http://en.wikipedia.org/wiki/Builder_pattern

The builder pattern can be used where the complete product cannot be built at one shot. For example consider a FeedBuilder which builds feed of a specific data. The raw data records is transformed into a flat file. The raw data records are added into the FeedBuilder as data is processed. Finally when all the data is added into the FeedBuilder, the Feed reference is obtained from the FeedBuilder by the Director.

No comments: