作者:PeterXu 来源:Blog.CSDN Blog: http://blog.csdn.net/peterreg/
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。本文地址:http://blog.csdn.net/peterreg/archive/2008/04/02/2243123.aspx
使用静态工厂模式,通过传入枚举型参数 ,动态创建访问实例
实现模式上采用基本实现接口,派生类继承基类的虚函数,从而实现代码的耦合较低,有很好的扩展性。
public
enum
DBType
... {
Access,
SQL,
DB2,
Oracle,
MySQL
}
public static class DBAccessFactory
... {
public static IDBAccess Create(DBType type)
...{
IDBAccess IRet = null;
switch (type)
...{
case DBType.Access:
IRet = new Access(type);
break;
case DBType.SQL:
IRet = new SQL(type);
break;
default:
break;
}
return IRet;
}
private abstract class DBAccess : IDBAccess
...</
... {
Access,
SQL,
DB2,
Oracle,
MySQL
}
public static class DBAccessFactory
... {
public static IDBAccess Create(DBType type)
...{
IDBAccess IRet = null;
switch (type)
...{
case DBType.Access:
IRet = new Access(type);
break;
case DBType.SQL:
IRet = new SQL(type);
break;
default:
break;
}
return IRet;
}
private abstract class DBAccess : IDBAccess
...</