设计模式之抽象工厂模式(Abstract Factory)
2020-05-07 本文已影响0人
杨斌_1024
概述
The Abstract Factory provides an interface for creating families of related or dependent objects without the need to specify their concrete classes.
意思是抽象工厂提供一个接口,这个接口可以创建一系列相关依赖的对象,并且不用指定他需要创建的哪一个具体的类。总而言之,就是一个抽象接口可以获取好几种不同类别的对象。
菜鸟教程的例子很好

最重要的一步是

In the example above, the ShapeFactory can be used to create objects based on the String shapeType. So, we do not need to specify the concrete class, but only need to pass the type string. This pattern uses inheritance to define the factories that create objects.
