62,047
社区成员
发帖
与我相关
我的任务
分享
public interface IDAL
{
int Add();
int Update();
int Delete();
}
public class NewsDAL : IDAL
{
}
public class PhotoDAL : IDAL
{
}
class factory
{
public static IDAL GetDAL(string category)
{
switch (category)
{
case "news": return new NewsDAL(); break;
case "photo": return new PhotoDAL(); break;
......
}
}
}
public interface IBaseDAL<T> where T : BaseModel, new()
{
int Add(T model);
int Update(T model);
int Delete(T model);
}
class factory
{
public static IBaseDAL<BaseModel> GetDAL(string category)
{
switch (category)
{
case "news": return new BaseDAL<News>(); break;
case "news": return new BaseDAL<Photo>(); break;
}
}
}
class factory{
public static IBaseDAL<T> GetDAL<T>(){
if(typeof(T)==typeof(News)){
return (IBaseDAL<T>)new BaseDAL<News>();
}else if (typeof(T)==typeof(Photo)){
return (IBaseDAL<T>)new BaseDAL<Photo>();
}
return null;
}
}