转载请注明出处,谢谢!
using System;
namespace iuhxq
{
public abstract class DataProvider
{
public abstract string GetDataProvider();
}
public class OleDbDataProvider : DataProvider
{
public override string GetDataProvider()
{
return "OleDbDataProvider";
}
}
public class SqlDataProvider : DataProvider
{
public override string GetDataProvider()
{
return "SqlDataProvider";
}
}
public class DataProviderFactory
{
public static DataProvider GetDataProvider(string ProviderType)
{
if (ProviderType.ToLower() == "oledbdataprovider")
{
return new OleDbDataProvider();
}
else
{
return new SqlDataProvider();
}
}
}
public class Factory
{
public static void Main()
{
Console.WriteLine(DataProviderFactory.GetDataProvider("OleDbDataProvider").GetDataProvider());
}
}
}