C # object-oriented design mode Lecture 3: abstract factory pattern Abstract Factory mode (Creation Mode)

Source: Internet
Author: User

(According to the msdn webcast courses)

New Problem: Implementing dependencies cannot cope with changes in the specific instantiation type. (When the instance object changes, it cannot meet the requirements)

Example:

When a road is prone to change and may become a mudroad, You need to modify all the new to road locations in the system.

Solution:

Closed change point-where to change and where to close; if the new type is relatively stable, there is basically no need to encapsulate it.

The created object is easy to change, so it is necessary to encapsulate the process of object creation.

Interface-Oriented Programming: Dependent interfaces instead of dependency implementation

Abstract The road classes, create a series of different types of child classes, and instantiate them in the createxx aspect as needed. Benefits: customers are not affected when changes are required.Program, You only need to modify the class library.

Create a series of mutually dependent objects

Problems with this simple factory:

It cannot cope with changes to "objects dependent on different series. For example, the border skin of different styles is usually a set of dependent objects. When the style changes, these objects should change accordingly.

Solution:

Or encapsulation changes. A plug-in mechanism is provided to avoid tight coupling between the customer program and the creation of specific objects in multiple systems.

Gof: provides an interface for this interface to create a series of "related or interdependent objects" without specifying their specific classes.

Producta and B are specific to the series 1 and 2, respectively, and the two products in the series are mutually dependent. They are instantiated through concreterfactory1 and 2. The customer program only needs to operate the three interfaces provided by the class library to instantiate different series of products.

Abstract Factory mode:

The change is the combination of different styles and series, rather than the increase or decrease of specific product objects or various parts within the product.

Conclusion

Related Article

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.