Difference between factory pattern and AbstractFactoryPattern?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   manikandan_chipcd
Posted On:   Friday, February 29, 2008 04:16 AM

Difference between factory pattern and AbstractFactoryPattern?

Re: Difference between factory pattern and AbstractFactoryPattern?

Posted By:   Stephen_McConnell  
Posted On:   Friday, February 29, 2008 09:38 AM

I got this off JavaRanch:


Factory Pattern:


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.


There are several similar variations on the factory pattern:



  1. The base class is abstract and the pattern must return a complete working class.

  2. The base class contains default methods and is only subclassed for cases where the default methods are insufficient.

  3. Parameters are passed to the factory telling it which of several class types to return. In this case the classes may share the same method names but may do something quite different.



Abstract Factory Pattern:



The Abstract Factory pattern is one level of abstraction higher than the factory pattern. You can use this pattern when you want to return one of several related classes of objects, each of which can return several different objects on request. In other words, the Abstract Factory is a factory object that returns one of several factories.


Note: There was a long discussion on the thread about whether a Factory Pattern was really a "Gang of Four" design pattern. But as a devloper, I really don't care. I use the Factory Design pattern AND the AbstractFactory Design pattern.. and when I talk to other developers that know Design Patterns they know what I'm talking about when I say "I used the Factory Pattern to implement this..."


Hope this helps.


Stephen McConnell

About | Sitemap | Contact