1
使用工厂模式,我有两个班返回对象和列表<object>在C#
public class LoginModel : IBaseInterface
{
public string EmailAddress { get; set; }
public string Password { get; set; }
}
和
public class UsersModel : IBaseInterface
{
public int UserID { get; set; }
public string UserName { get; set; }
public string EmailAddress { get; set; }
public int RoleID { get; set; }
public string RoleName { get; set; }
public int ProjectID { get; set; }
public string ProjectName { get; set; }
public int PMID { get; set; }
public string PMEmailAddress { get; set; }
public string PMEmailName { get; set; }
public int DMID { get; set; }
public string DMEmailAddress { get; set; }
public string DMEmailName { get; set; }
}
IBaseInterface是intergace,有没有什么定义。
public static IBaseInterface Create(ObjectsCollection Type)
{
switch (Type)
{
default:
return null;
case ObjectsCollection.UsersModel:
return new UsersModel();
case ObjectsCollection.LoginModel:
return new LoginModel();
}
}
一切工作正常的对象。但是如何使用这个工厂返回List<UsersModel>
和List<LoginModel>
?
如果有人请帮我解决这个问题,会不错。
感谢
只是增加ObjectsCollection是一个枚举: 公共枚举ObjectsCollection { UsersModel, LoginModel } – Anurag
可能的话,你的问题是这不是使用工厂模式的好方法吗?也许你需要2个工厂,一个用于物品,一个用于收集物品?我怀疑你不应该使用任何一种,只是在你想要的地方新增你想要的东西。 – Neil
我想这个工厂也返回列表类型的对象。 – Anurag