抽象工厂模式是对一系列产品的统一和管理
公共工厂接口
- public interface Creator{
- public ProductA factoryA();
- public ProductB factoryB();
- }
具体工厂类1
- public class ConcreteCreator1 implements Creator{
- public ProductA factoryA(){
- return new ProductA1();
- }
- public ProductB factoryB(){
- return new ProductB1();
- }
- }
具体工厂类2
- public class ConcreteCreator2 implements Creator{
- public ProductA factoryA(){
- return new ProductA2();
- }
- public ProductB factoryB(){
- return new ProductB2();
- }
- }
抽象产品类A
- public interface ProductA { }
抽象产品类B
- public interface ProductB { }
具体产品类ProductA1
- public class ProductA1 implements ProductA { }
具体产品类ProductA2
- public class ProductA2 implements ProductA { }
具体产品类ProductB1
- public class ProductB1 implements ProductB { }
具体产品类ProductB2
- public class ProductB2 implements ProductB { }