官术网_书友最值得收藏!

Abstract factory

The abstract factory is an extended version of the factory method. Instead of creating a single type of object, it is used to create a family of related objects. If the factory method had one AbstractProduct, the abstract factory has several AbstractProduct classes.

The factory method has an abstract method that is implemented by each concrete factory with the code to instantiate the abstract product. The abstract factory has one method for each abstract product.

If we take the abstract factory pattern and we apply it to a family containing a single object, then we have a factory method pattern. The factory method is just a particular case of the abstract factory.

The implementation of an abstract factory pattern is described in the following class diagram:

The abstract factory pattern is composed of the following classes:

  • AbstractFactory: This is the abstract class that declares the methods that are creating types of products. It contains a method for each AbstractProduct that has to be created.
  • ConcreteFactories: Concrete classes that implement the methods declared in the AbstractFactory base class. There is a factory for each set of concrete products.
  • AbstractProducts: The base interfaces or classes for objects that are required. A family of related products is made up of similar products from each hierarchy: ProductA1 and ProductB1 are from the first family of classes, which is instantiated by ConcreteFactory1; the second family, ProductA2 and ProductB2, is instantiated by ConcreteFactory2.
主站蜘蛛池模板: 台州市| 清水河县| 肥东县| 灵山县| 金川县| 天峻县| 靖远县| 元谋县| 含山县| 乐东| 桑植县| 阿克| 汝州市| 昆山市| 英超| 平江县| 苏尼特左旗| 元谋县| 新晃| 广饶县| 迭部县| 青浦区| 辉县市| 林芝县| 洞口县| 金川县| 腾冲县| 六安市| 余江县| 驻马店市| 泸定县| 墨竹工卡县| 内丘县| 东乌珠穆沁旗| 德昌县| 通城县| 于都县| 临汾市| 中西区| 怀宁县| 泽州县|