Builder Pattern

Posted: April 12, 2014 in Creational Patterns, Design Patterns
Tags: , ,

Builder pattern is all about separating the object construction from its representation. Below is the definition given by GOF in their classic design patterns book,

“Separate the construction of a complex object from its representation so that the same construction process can create different representations”.

Parse a complex representation, create one of several targets.

UML Class Diagram

1

participants

The classes and/or objects participating in this pattern are:

  • Builder  (IPhoneBuilder)
    • specifies an abstract interface for creating parts of a Product object
  • ConcreteBuilder  (AndroidPhoneBuilder, ApplePhoneBuilder, WindowsPhoneBuilder)
    • constructs and assembles parts of the product by implementing the Builder interface
    • defines and keeps track of the representation it creates
    • provides an interface for retrieving the product
  • Director  (Manufacturer)
    • constructs an object using the Builder interface
  • Product  (MobilePhone)
    • represents the complex object under construction. ConcreteBuilder builds the product’s internal representation and defines the process by which it’s assembled
    • includes classes that define the constituent parts, including interfaces for assembling the parts into the final result

In this video I have discussed about overview of Builder Pattern and need of going for Builder Patter with the help of code samples. Later explained Builder pattern with the help of Mobile Phone Manufacturing System example.

Sometimes creational patterns are complementary: Builder can use one of the other patterns to implement which components get built. Abstract Factory, Builder, and Prototype can use Singleton in their implementations.

Builder focuses on constructing a complex object step by step. Builder returns the product as a final step, but as far as the Abstract Factory is concerned, the product gets returned immediately

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s