Design patterns -- Notes on abstract factory patterns

clionlin 2022-05-22 11:57:06 阅读数:934

designpatternsnotesabstractfactory

An abstract factory , A brand can have two products to be produced in this abstract factory
 Insert picture description here

The functions that industry standard mobile phones need to realize
 Insert picture description here

Which brand of products do customers choose , You can place an order if you get the products under this brand , Then the brand factory starts to produce the products required by customers ( Mobile phone or router )

 Insert picture description here

When the goods are received, the customer can use the functions of the product
 Insert picture description here

The advantages of abstract factory pattern

  • Separate interface and Implementation
    The client uses the abstract factory to create the required objects , And the client doesn't know who the implementation is at all , The client is just product oriented interface programming . in other words , The client is decoupled from the specific product implementation .

  • Make it easy to switch product families
    Because a specific factory implementation represents a product family , For example, in the above example, from Xiaomi series to Huawei series, you only need to switch specific factories .

Disadvantages of the abstract factory pattern

  • It's not easy to expand new products
    If you need to add a new product to the entire product family , Then you need to modify the abstract factory , This will result in modification of all factory implementation classes .
copyright:author[clionlin],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/142/202203140552568698.html