design pattern

Hi all,I want to know what is the difference between factory pattern and builder pattern.Please express your views.Both are looking same to me.with regards,ajse
[188 byte] By [ajseajsea] at [2007-10-2 16:26:21]
# 1

not sure if 'm correct here.

Builder pattern are usually us when you need to create an object using multiple step. like Creating a car, you create th eengine, tire, tec..and put together the car. the step to creating the car can be different each time.

public Car createCamry(){

Engine e = new TurboEngine();

Tire tire = new Tire();

Camry c = new Camry();

c.addEnhine(e);

// etc

return Car

}

In Factory, you generally create the object in one step..

public Car createCamry(){

return new Camry();

}

tnguyen1973a at 2007-7-13 17:25:53 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

You are right Both of these patterns are creational design patterns Purpose of these two patterns is very different as Abstract Factory Patterns (which is commonly known as Factory pattern ) is used to create a object in a scenario when you have a product & there is a possibility of many vandors providing implementation for it. So it is good to come up with a abastract factory which provides create method for the product. Each vendor can implement you abstract factory & provide a concrete implementation which will return a product of Vendor implementation.

Builder patter is used in case you have a very complex object creation process involved & you realy want to abstract the client from doing all those complex steps. In such situation you create a builder class which takes care of all complex steps & client just needs to use this builder class to create your complex object.

Hope it clarifies your doubts.

joshisachin79a at 2007-7-13 17:25:53 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
hi, Vending Machine is best Example for Builder Patttern. say for example when you want Tea Vending machine do the process which is adding hot water,milk and sugar u consider these are methods like AddSugar. the end result is Tea what u need.
Gancya at 2007-7-13 17:25:53 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
The shortest answer would be "Builder separates the construction of complex objects from their representation."
kilyasa at 2007-7-13 17:25:53 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
> The shortest answer would be "Builder separates the> construction of complex objects from their> representation." http://www.programmersheaven.com/articles/faisal/pattern.htm
kilyasa at 2007-7-13 17:25:53 > top of Java-index,Other Topics,Patterns & OO Design...
# 6
someone said that we can easily combine abstract factory and builder pattern.I tried and is littlebit confused.Will anyone of you suggest me how to do it?
siji@infotecha at 2007-7-13 17:25:53 > top of Java-index,Other Topics,Patterns & OO Design...
# 7

> > The shortest answer would be "Builder separates

> the

> > construction of complex objects from their

> > representation."

>

> http://www.programmersheaven.com/articles/faisal/patte

> rn.htm

Yuck, what was that, .net?

Try a java one: http://www.fluffycat.com/java-design-patterns/

LumpyNosea at 2007-7-13 17:25:53 > top of Java-index,Other Topics,Patterns & OO Design...