This is my blog , it could contain various topics from my own thoughts to computer programming ....

Monday, May 13, 2013

Going technical...Builder pattern

"House" when I say this word I know many of you would imagine the place where you are currently living or the place where you lived when you were a kid. It is likely that two different individuals may have two different versions of the house that they are familiar with. But still the basic steps followed for the construction of those houses remain the same. Well now you must be thinking what those basic steps that I am talking about.

When a house is built regardless of the outside appearance of the house one must follow a fundamental sequence of actions to complete the house.

1. Dig the land for foundation

2. Lay the foundation

3. Construct columns and beams

4. Construct side walls or partition walls

5. Fix the roof

In general any house that you can think of must have gone through the above stages of construction. Now that we are clear of the fact that we can generalize the process of constructing a house. We could identify this as a set of stages that must be followed to construct any house.

I guess now you are becoming clearer and clearer of what the title says. "Builder Pattern". So our builder will follow the above sequence and will successfully be able to build a house. If we introduce set of builders which follow the same steps of construction but add some additional touch to the final outcome we could have houses with different appearance.

How are we going to use this in software design. Yes , enough talking start coding then....
public class House {

public static void main(String[] args) {
System.out.println("Village House :");
//Build a Village House
HouseBuilder builder = new VillageHouseBuilder();
House house = buildHouse(builder);
//
System.out.println("City House :");
//Build a City House
builder = new CityHouseBuilder();
house = buildHouse(builder);
}