Design Pattern note-factory

Source: Internet
Author: User

For consultationDipIn many cases, it cannot be associated with a specific class instance.NewKeywords violate this principle. Of course, some classes will not change, suchStringThere is no need to isolate these items. If the specific class is very variable, the dependency will cause problems. How can we avoid using the specific class?Factory.

FactoryThe general meaning of the mode is that the role of creating a specific class instance is handled by the "factory class" and corresponding interfaces are returned. You only need to operate these abstract interfaces, to isolate dependencies with specific classes.

In. NetIn enterprise development, this mode is most commonly used.DalLayer components. In this mode, you can create correspondingDalInstance.ProgramYou can easily create applications that support multiple databases. This application is analyzed as an example.

This model is used inDalLayer mechanism:

Where:

BllA group of called clients, which callDalfactoryReturns the correspondingIdalOperation Method.

IdalA group of method interfaces called by the customer, such as the return order number.

DalfactoryFor the factory classBllCall the corresponding static method and return the correspondingIdalImplementation class instance.

Sqlserverdal,OracledalImplementationDalOfSqlserverImplementation andOracleImplementation: there is a way to deal directly with the database.

 

In this way,DalfactoryBy reading the configuration file. NetReflection mechanism to create an instance of the corresponding database. For the designed software, you only need to change the corresponding configuration to change the database.

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.