During product project implementation, we will inevitably encounter different functions because the project service objects are different.
In this way, it is time-consuming to recompile the entire solution after each modification.
In fact, with the static factory, we can easily introduce additional dll to dynamically configure the implementation of these functions.
The following are the base classes of all factories, including a method for reading the configuration file and a static method for generating objects.
Code
/// <Summary>
/// All factory base classes
/// <Author name = "Jan. David"> </author>
/// <! [CDATA [2010-11-05]>
/// </Summary>
Public Abstract ClassAbstractFactory
{
/// <Summary>
///Read the value in the set file
/// </Summary>
/// <Param name = "parentNode"> </param>
/// <Param name = "key"> </param>
/// <Returns> </returns>
Public Static StringReadSettring (StringParentNode,StringKey)
{
StringFilePath=AppDomain. CurrentDomain. BaseDirectory;//Project path
//Create an xml Document Object
System. Xml. XmlDocument doc= NewSystem. Xml. XmlDocument ();
//Read document
Doc. Load (FilePath+ "/Setting. xml");
//Get Root Node
System. Xml. XmlNodeList Root=Doc. FirstChild. NextSibling. ChildNodes;
System. Xml. XmlNodeList nodes= Default(System. Xml. XmlNodeList );
Foreach(System. Xml. XmlNode nodeInRoot)
{
If(Node. Name. ToLower ()=ParentNode. ToLower ())
{
Nodes=Node. ChildNodes;
Break;
}
}
If(Nodes! = Null &&Nodes. Count> 0)
{
Foreach(System. Xml. XmlNode nodeInNodes)
{
If(Node. Attributes ["Name"]. Value. ToLower ()=Key. ToLower ())
{
ReturnNode. Attributes ["Value"]. Value;
}
}
}
Return Null;
}
/// <Summary>
///Instantiate an object
/// </Summary>
/// <Typeparam name = "T">Type to be instantiated</Typeparam>