// abstract
public interface IProduct {
void doSomething();
}
// real product
public class ProductA implements IProduct {
public void doSomething(){
// ...
}
}
// real product
public class ProductB implements IProduct {
public void doSomething(){
// ...
}
}
FACTORY
public class Creator {
public static IProduct factory(String product) {
if (product.equals('a')) {
return new ProductA();
}
else if(product.equals('b')) {
return new ProductB();
}
}
}
CLIENT
public class Consumer{
public static void main(String[]] args) {
Creator creator = new Creator();
IProduct product = creator.factory(args[0]);
//then consumer start using this product
product.doSomething();
}
}