public class SimpleFactory {
public static Product createProduct(String type) {
if ("A".equals(type)) {
return new ConcreteProductA();
} else if ("B".equals(type)) {
return new ConcreteProductB();
}
return null;
}
}
public interface Factory {
Product createProduct();
}
public class ConcreteFactoryA implements Factory {
public Product createProduct() {
return new ConcreteProductA();
}
}
public class ConcreteFactoryB implements Factory {
public Product createProduct() {
return new ConcreteProductB();
}
}
public interface AbstractFactory {
Product1 createProduct1();
Product2 createProduct2();
}
public class ConcreteFactory1 implements AbstractFactory {
public Product1 createProduct1() {
return new ConcreteProduct1A();
}
public Product2 createProduct2() {
return new ConcreteProduct2A();
}
}
public class ConcreteFactory2 implements AbstractFactory {
public Product1 createProduct1() {
return new ConcreteProduct1B();
}
public Product2 createProduct2() {
return new ConcreteProduct2B();
}
}