• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Abstract Factory Pattern Vs Factory Pattern

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the main difference between AbstractFactory Pattern and Factory Pattern? And advantages of Abstract Factory pattern?

However i can create a super class and extens it with subclasses.
And both pattern are abstract in nature.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With Factory Method the client expects an implementation of an interface or abstract class but doesn't know exactly what concrete class the factory will return.

With AbstractFactory the client doesn't even know what factory it's going to use. First it gets a factory (from a factory factory I suppose) and then it calls a factory method.

Our classic example is a GUI widget factory. If you want to have plug-in look & feel sets, you might have a widget factory implementation per style and do something like:

WidgetFactory is an interface for an abstract factory. getButton() is a factory method.

These patterns are confusingly named and they bug almost everyone at first. Hope that helps!
[ March 01, 2005: Message edited by: Stan James ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does the Factory pattern come from? It's not a GoF pattern, as far as I can tell.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I edited that to Factory Method.
 
Divya Mehrotra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:
Where does the Factory pattern come from? It's not a GoF pattern, as far as I can tell.



I have read about it in a book "Design Pattern" by James W. Cooper. Here in this book , there a Facorty Pattern defined under creational pattern section.

According to that book :-


A Factory pattern is one that returns an instance
of one of several possible classes depending on the data provided to it.
Usually all of the classes it returns have a common parent class and common
methods, but each of them performs a task differently and is optimized for
different kinds of data.



Purpose of Factory Pattern:-



In this pattern , user creates an abstraction which decides which of several possible classes to return and returns one. Then user calls the methods of that class instance without ever knowing which derived class user is actually using. This approach keeps the issues of data dependence separated from the classes´┐Ż useful methods.



and I wanted to know:-

I am able to implement the same logic either with factory pattern or with Abstract factory pattern. I can create a super class which will return the instance of all the factories and which in turn can create the objects.

So if this is the scenario, then what is the actual difference between them?
 
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
I think I understand - thanks for the elaboration.

A Factory decides between different implementations based on parameters passed to it. An example for a Factory than would be JDBC's DriverManager. There is only one DriverManager object, wich can create different kinds of Connections, based on the JDBC URL passed to it.

The Driver (used internally), on the other hand, is an Abstract Factory. There is a Driver interface defined, which gets implemented by different JDBC implementations. Every implementation creates (assumedly) only one type of Connection - which type you get is not based on some parameter, but based on which implementation you use.

Does that help?
[ March 02, 2005: Message edited by: Ilja Preuss ]
 
Divya Mehrotra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot for clearing the doubts.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic