Abstract Factory Model

Source: Internet
Author: User

Abstract Factory Model
Abstract Factory Model

Intent: provide an interface for creating a series of related or mutually dependent objects without specifying their specific classes.

Practicality

  • A system must be independent of the creation, combination, and representation of its products.
  • A system must be configured by one of multiple product generations.
  • When you want to emphasize the design of a series of related product objects for joint use.
  • When you provide a product class library, instead of displaying their interfaces.

    Structure

    Abstract Factory has multiple factory methods. The number of factory methods is generally the number of object product types. Products returned from the same factory method are generally used together. The abstract factory mode is usually implemented using the factory method mode, or Prototype. A specific factory is usually Singleton.

    Participants

    • AbstractFactory: declares an operation interface for creating a series of product objects.
    • ConcreteFactory: allows you to create specific product objects.
    • AbstractProduct: declares an interface for a type of product object
    • ConcreteProduct: Define a product object created by a specific factory.
    • Client: Only interfaces declared by the AbstractFactory and AbstractProduct classes are used.

      Collaboration
      -Create a ConcreteFactory class instance at runtime. This specific factory creates a specific product object. To create different product objects, customers should use different factories.
      -AbstractFactory delays the creation of product objects to its ConcreteFactory subclass.

      Effect
      -It separates specific classes. The Abstract Factory mode helps you control the classes of objects created by an application.
      -It makes it easy to switch between product series. A specific factory class only appears once in an application-that is, when it is initialized.
      -It facilitates product consistency.
      -It is difficult to support new types of products, and to expand abstract factories to produce new types of products

      Abstract Facotry mode in JDK
      • Recognizeable by creational methods returning the factory itself which in turn can be used to create another abstract/interface type. (javadoc classes have 'factory ')
        • Javax. xml. parsers. DocumentBuilderFactory # newInstance ()
        • Javax. xml. transform. TransformerFactory # newInstance ()
        • Javax. xml. xpath. XPathFactory # newInstance ()
        • DatagramSocketImplFactory, PreferencesFactory
        • Java. SQL interfaces all get their concrete implementations from JDBC JAR when driver is registered.
        • An abstract factory has multiple factory methods, each creating a different product. the products produced by one factory are intended to be used together (your printer and cartridges better be from the same (abstract) factory ). as mentioned in answers abve the families of awt gui components, differing from platform to platform, are an example of this (although its implementation differs from the structure described in Gof ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.