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

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.
主站蜘蛛池模板: 高尔夫| 红原县| 射阳县| 武定县| 河池市| 枣庄市| 霸州市| 英德市| 扶余县| 安塞县| 汨罗市| 梅河口市| 甘南县| 桂平市| 平阳县| 岚皋县| 大田县| 施秉县| 伊金霍洛旗| 瓦房店市| 于田县| 望都县| 广丰县| 赤水市| 德安县| 崇明县| 安图县| 偏关县| 长顺县| 宜章县| 宿州市| 永城市| 渝北区| 兴山县| 饶平县| 永吉县| 荃湾区| 永善县| 郁南县| 普兰店市| 景谷|