美文网首页Java设计模式程序员
设计模式之抽象工厂模式(Abstract Factory)

设计模式之抽象工厂模式(Abstract Factory)

作者: DevelopJavaer88 | 来源:发表于2020-05-07 21:34 被阅读0次

概述

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.

根据抽象接口获取颜色

本文GitHub代码地址    

推荐看这篇文章

相关文章

网友评论

    本文标题:设计模式之抽象工厂模式(Abstract Factory)

    本文链接:https://www.haomeiwen.com/subject/tnvzghtx.html