• 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 Factory Pattern

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What exactly is the difference between a Factory and a Builder pattern?

Thanks in advance.

Regards
GC
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A factory method returns an object whose concrete type is not necessarily known. For example a factory method that promises to return an Appliance might return a Toaster or a Blender. In a more serious world, it might return a DatabasePersistanceEngine or a FileSystemPersistanceEngine. The caller only cares that the base type or interface is satisfied, and can work equally well with whatever concrete type comes back.

A builder goes through several steps to construct a more complex object or graph of objects. A factory method could certainly use a builder to make the thing it returns, or you could use a builder without a factory method.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With other words, an Abstract Factory typically has a number of methods all returning a different kind of object, whereas a Builder has a number of methods used to specify the kind of object to build, and one method used to finally return that object.
reply
    Bookmark Topic Watch Topic
  • New Topic