abstract class AbstractProductA { } abstract class AbstractProductB { } class ProductA1 extends AbstractProductA { } class ProductA2 extends AbstractProductA { } class ProductB1 extends AbstractProductB { } class ProductB2 extends AbstractProductB { } abstract class AbstractFactory { public abstract AbstractProductA createProductA(); public abstract AbstractProductB createProductB(); } class Factory1 extends AbstractFactory { @Override public AbstractProductA createProductA() { return new ProductA1(); } @Override public AbstractProductB createProductB() { return new ProductB1(); } } class Factory2 extends AbstractFactory { @Override public AbstractProductA createProductA() { return new ProductA2(); } @Override public AbstractProductB createProductB() { return new ProductB2(); } } public class Client { public static void main(String[] args) { AbstractFactory factory1 = new Factory1(); AbstractFactory factory2 = new Factory2(); AbstractProductA a1 = factory1.createProductA(); AbstractProductA a2 = factory2.createProductA(); AbstractProductB b1 = factory1.createProductB(); AbstractProductB b2 = factory2.createProductB(); } }