Design Patterns-Abstract Factory

Source: Internet
Author: User
The abstract factory mode may be ProgramThe most familiar design pattern of the Members. It usually seems that no hero is talking about this (maybe afraid of price loss), especially in. under the net development platform, the light of the abstract factory has long been covered by reflection technology, and the status of the abstract factory model has gradually declined, gradually fading out our sight.
The purpose of the abstract engineering mode is to provide an interface for creating correlated or dependent objects or object families. The main purpose of the abstract factory is to strip the dependency between the consumer of the object and the specific object, so that the object can be changed without touching the consumer of the object.
A key point or necessary condition for using an abstract factory is that the objects to be created are related or mutually dependent. For example, a random image production factory needs to create a background for the image. The interface is as follows:
Public interface istagefactory
{
Public ibackground createbackground ();
Public iforeground createforeground ();
}
Because the two objects created in this scenario are directly correlated, the prospect of a fish cannot be displayed on the desert background.
If there is no correlation or dependency between the created objects, do not use the abstract factory. In this application scenario, the abstract factory is a collection object, introduce unnecessary dependencies to the consumer of the factory interface (maybe the use class of a factory does not need to depend on a type created by the factory at all), and does not meet the single responsibility principle. In addition, the laziness of programmers may combine the responsibilities of creating more unnecessary types into the factory interface.
However, if the created object is correlated or interdependent, it is best to use the abstract factory mode. Although reflection can achieve the same purpose, reflection constraints are not mandatory, errors may be introduced in the configuration information, making it difficult to track and discover bugs.

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.