2 回答

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
根據(jù)代碼,對(duì)我來(lái)說(shuō),示例似乎表明您希望為用戶維護(hù)單獨(dú)的實(shí)現(xiàn),然后返回所需的實(shí)現(xiàn)。
public interface IStudentFactory
{
IUser Create();
}
public class StudentFactory
{
public IUser Create() => new StudentContext();
}
然后根據(jù)您在 IUser 接口中的實(shí)現(xiàn),您可以連接到您的數(shù)據(jù)存儲(chǔ)來(lái)管理這些類型的用戶。
var context = new StudentFactory().Create())
var students = context.GetAllStudents();
context.Students.Add(new Student() { });
我提供的方法是基于您希望能夠訪問有關(guān)不同類型用戶的信息、持久化和管理的概念。您的示例顯示了您正在添加的原始集合,可能會(huì)處理其他功能,但我想您正在努力實(shí)現(xiàn)更一致的東西。
我可能不符合你的意圖,但這就是我的解釋。
- 2 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)