SIGN UP MEMBER LOGIN:    
ARTICLE

Builder Pattern - A Robot Example

Posted by Jean Paul Articles | Design & Architecture October 08, 2010
In this article I am trying to demonstrate the usage of Builder Pattern using a Computer Assembling Robot. Builder Pattern is one among the 23 patterns by Gang Of Four.
Reader Level:
Download Files:
 

In this article I am trying to demonstrate the usage of Builder Pattern using a Computer Assembling Robot. Builder Pattern is one among the 23 patterns by Gang Of Four.  

Definition of Builder

The GoF says that the Builder design patterns let you "Separate the construction of a complex object from its representation so that the same construction processes can create different representations."

Problem to Solve

In a computer manufacturing unit, depending on the configuration – they have to create computers.  The challenge is that the computer parts are chosen in the runtime.  The order can contain n number of computers based on the same configuration.  This could be the right example to implement the Builder pattern where each robot will be setup with a particular computer configuration.  The robot will continue creating the same configuration based computer n times.

Computer Peripherals

Processor:   Intel / AMD
Monitor: Samsung / LG
Speakers: None / Stereo / Surround

Execution

The Windows Form UI allows the user to choose the configuration.  The virtual factory provides up to 3 robots to be added before the actual assembling takes place.

1.gif
 
Code Explained

Following is the screen shot of the main class named Robot.  The class contains a property called Peripherals which can be used to configure the peripherals added: like CPU as Intel, Monitor as Samsung etc.

After adding the peripherals, we can call the Create() method.  It will iterate through the Peripherals dictionary and calls the appropriate methods to integrate the peripherals.  This allows us to choose the peripherals at run time as well as the sequence too.  

If the Peripheral dictionary contains CPU then the AssembleCPU() method is invoked.

If the Peripheral dictionary contains Monitor then the AssembleMonitor () method is invoked.

2.gif

The class Peripheral is an enumeration as following:

    public enum Peripheral

    {

        Processor,

        Monitor,

        Speakers

    }

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks Navatha for taking a moment to comment!
Surely I will try myself to come up with more interesting apps.

Posted by Jean Paul Oct 20, 2010

ALL THE BEST


Posted by navatha rao Oct 20, 2010

Thank You Mahesh for encouraging me.

Regards,
Jean Paul

Posted by Jean Paul Oct 11, 2010

Thank you for sharing.

Posted by Mahesh Chand Oct 09, 2010
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Gauge for SharePoint
Become a Sponsor