GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE
Go To First  |  Previous Question  |  Next Question 
 J2EE  |  Question 13 of 104    Print  
What is the difference between Abstract Factory Pattern and factory Pattern?
What is the difference between Abstract Factory Pattern and factory Pattern? When would you use each of them?


  
Total Answers and Comments: 3 Last Update: March 19, 2006     Asked by: santanu 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 14, 2006 15:57:11   #1  
LakshmiKanth        

RE: What is the difference between Abstract Factory Pa...

Abstract Factory:- provide an interface to create a family of related or dependant classes without specifying their concrete classes

Factory Method :- another creational pattern Defines an interface for creating An Object but let sub class decide which class to instantiate


 
Is this answer useful? Yes | No
March 13, 2006 23:16:51   #2  
gcharan Member Since: March 2006   Contribution: 1    

RE: What is the difference between Abstract Factory Pa...

Abstract Factory : As the name suggest its not a concrete factory infact it acts as the factory for factories. For e.g. suppose we have some factories for creating AWT components and each factory works on a particular OS. In this case we can write an Abstract Factory which has some abstract methods to be implemented by all subclass concerete factories and this abstract factory also has a static method to get the appropriate factory based on some arguments.

Here is a small example for the same.

public abstract class AbstractFactory implements FactoryInterface {

private static FactoryInterface factory;

public static FactoryInterface getFactory(int index) {

if (index 1) {

factory new Factory1();

} else {

factory new Factory2();

}

}

}

public class Factory1 extends AbstractFactory {

//implements methods in FactoryInterface

}

public class Factory2 extends AbstractFactory {

//implements methods in FactoryInterface

}

Hope it will help to understand the concept.

Regards

Ashish.


 
Is this answer useful? Yes | No
March 19, 2006 12:39:27   #3  
rkj2ee2005 Member Since: March 2006   Contribution: 4    

RE: What is the difference between Abstract Factory Pa...
Abstract factory pattern is typically used for giving implementation to specification (eg. jdbc servlet specifications etc...). Factory pattern is used when you want to defer object creation to later stages (when concrete implementation of that class/interface is not known or there could be multiple ways to implement and want to give flexibility over it) but keep continuing developing framework/rest of the application.RegardsRama
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape