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.