aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Difference between builder and abstract factory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Difference between builder and abstract factory" Watch "Difference between builder and abstract factory" New topic
Author

Difference between builder and abstract factory

kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
HI All
What is the exact diff between BUilder and abstract factory??
THanks
kundan


SCJP1.4,SCBCD,SCEA,CNA
Failures are practice shoots for success.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

An Abstract Factory is a parent class for many different types of Factories. So for instance you have an Abstract PaintFactory. There are many different types of colors, that will be what each implementation factory will create. But paint also different types of makers, like Sherman-Williams, Behr to name two. So we can then create a ShermanWilliamsPaintFactory and a BehrPaintFactory that will implement the Abstract Factory. You can put the commonality of all paint factories into the Abstract Factory, and just put in the unique differences within the implementation Factories.

So, a Builder is a class that takes many different Objects, combines them to make one type of Object, that needs all of that and build it for the caller. In some senses it is a Factory, but it only creates one type, most of the time.

Hope that helps, and hope I got it close.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
With an Abstract Factory, every method call creates and returns an object. You can reuse it to create as many objects as you like.

With a Builder, you specify the properties of *one* object with the method calls. Only the last method call will give you the built object. Typically you will have to create a new Builder for building the next object.

Does that help?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

With an Abstract Factory, every method call creates and returns an object.


I think you are thinking Abstract Method here, since the Factory in Abstract Factory is abstract, so you can't create an instance and call a method.

Mark
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Originally posted by Mark Spritzler:


I think you are thinking Abstract Method here, since the Factory in Abstract Factory is abstract, so you can't create an instance and call a method. i get those two confused all the time, and it is only because we looked at them both just yesterday that I remember this stuff.

Mark
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Mark Spritzler:


I think you are thinking Abstract Method here, since the Factory in Abstract Factory is abstract, so you can't create an instance and call a method.

Mark


Of course I meant that you'd have a concrete instance of a factory from the Abstract Factory pattern... :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between builder and abstract factory