• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between builder and abstract factory

 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI All
What is the exact diff between BUilder and abstract factory??
THanks
kundan
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic