Remark: Abstract Factory

Source: Internet
Author: User
Tags abstract interface
Yesterday I tried to say what I thought about the factory method. Today, the abstract factory.
In yesterday's post, for a factory class, we just defined a createproduct (), similar, we can also define CREATEPRODUCT1 () in the Factory, CreateProduct2 () A series of methods to create a product line related to this factory.
An example is a BBS access to the design. You can use the factory method to design a unified access interface for the Permissions section. You can refer to the Java Open Source Project Jive Forum.
Today I'm trying to talk about abstract factory patterns (abstracts factory).
In design mode, the abstract factory pattern is defined in this way:
Provides an interface to create a series of related and interdependent objects without having to develop their specific classes.
The one mentioned here creates a series of related and interdependent objects, referring to the factory method. So creating a factory interface without caring for a specific factory is a design idea that is abstract Factory mode. Abstract Factory mode allows us to replace a new product family in a program by configuring the Abstract factory interface with a different specific factory.
In other words, the factory is also abstracted, no longer a specific class, but a factory interface, it becomes an abstract factory.
The difference between the abstract factory and the factory method my feeling is very subtle. Just abstract factory considerations focus on a product series. And the factory method is a product. For example, you can set a factory method in a superclass and wait for a subclass to overwrite it, but the superclass can do something else at the same time. In an abstract factory, the abstract factory interface has only one function: the definition of a series of methods to create a series of products.

However, after a product line is created, it becomes difficult to add new product lines. Because the abstract factory interface has already been defined and has been published, it is not possible to change the defined product family in the interface (that is, a public series of createproduct methods), otherwise it will cause changes to the client code referencing the interface.





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.