File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between builder and abstract factory

 
kundan varma
Ranch Hand
Posts: 323
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All
What is the exact diff between BUilder and abstract factory??
THanks
kundan
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic