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