一个接口类库
IDAL(IOrder)
public interface IOrder { string GetOrder(); }
两个操作类库(均实现IDAL.IOrder接口)
SQLServerDAL(Order)
public class Order:IDAL.IOrder { #region IOrder 成员 public string GetOrder() { return "Order From SQLServer"; } #endregion }
OracleDAL(Order)
class Order:IDAL.IOrder { #region IOrder 成员 public string GetOrder() { return "Order From Oracle"; } #endregion }
一个工厂类库
DALFactory(Access)
public class Access
{ public static readonly string path=ConfigurationSettings.AppSettings["DAL"]; public static IDAL.IOrder CreateOrder() { //SQLServerDAL.Order sqlOrder = new SQLServerDAL.Order(); //return (IDAL.IOrder)sqlOrder; string className = path + ".Order"; return (IDAL.IOrder)Assembly.Load(path).CreateInstance(className); }
}
一个Web网站
protected void Page_Load(object sender, EventArgs e) { IDAL.IOrder order = DALFactory.Access.CreateOrder(); Response.Write(order.GetOrder()); }