抽象工厂模式建立父类的工厂,通过父类创建子类工厂,通过子类工厂创建对象。
本例中有两个接口Shape和Color,通过两个子工厂,ShapeFactory和ColorFactory,父类工厂FactoryProducer生成相应的子类工厂。
public interface Shape {
void draw();
}
public class Square implements Shape{
@Override
public void draw() {
System.out.println("Inside Square::draw() method.");
}
}
public class Rectangle implements Shape {
@Override
public void draw() {
System.out.println("Inside Rectangle::draw() method.");
}
}
public class Circle implements Shape {
@Override
public