Simple factory, Abstract factory

Source: Internet
Author: User

Iuserinfodal Userinfodal = Staticdalfactory.getuserinfodal ();//simple Factory mode better than the above
Simple factory//iuserinfodal Userinfodal = Staticdalfactory.getuserinfodal ();//simple Factory mode better than the above
Abstract Factory//iuserinfodal Userinfodal = Staticabstractfactory.getuserinfodal (); Abstract factory more advanced than simple factory

Namespace My.OA.DalFactory
{
Responsibilities: Build a factory model, a DAL Portal: As with the concept of context, get the context to manipulate the tables in the database and get the factory to manipulate all instances of his package

Factory: An idea, an instance, is widely called Through the factory, which is an object-oriented thinking, code reuse and high maintainability

Simple factory: How to generate or modify the code
public class Dalfactory
{
A dependency on abstract programming
public static Iuserinfodal Getuserinfodal ()
{
return new Userinfodal ();
}

}
Abstract Factory: Production mode does not modify the code (configuration), requires a more standardized writing naming specification
public class Staticabstractfactory
{
public static Iuserinfodal Getuserinfodal ()
{
The DAL instance is set by configuration
String dalassemblyname = system.configuration.configurationmanager.appsettings["Dalassemblyname"];
Requires a more standardized writing naming convention
Return Assembly.Load (Dalassemblyname). CreateInstance (Dalassemblyname + ". Userinfodal ") as userinfodal;//reflection is one of the ways in which abstract factories are implemented, just a thought
}

}
}

<appSettings>
<!--abstract Factory Create a database access layer instance with the assembly name--
<add key= "Dalassemblyname" value= "My.OA.DAL"/>
</appSettings>
<system.web>

Simple factory, Abstract factory

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.