目前我正在使用 ASP.NET MVC 4 和Code First Approach研究 C# 。我是 Visual Basic 开发人员,现在我想开始 C#。而且,现在我遇到了我必须管理多重继承的情况。但是,我认为 Class 是不可能的。那么,我应该如何管理我拥有的这些课程:
//I have the Following Person Class which Hold Common Properties
//and a Type of Person e.g : Student, Faculty, Administrative
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Type { get; set; }
}
//This is my Student Class, which is Derived from Person
public class Student : Person
{
public DateTime DateOfBirth { get; set; }
public DateTime EnrollmentDate { get; set; }
public string Remarks { get; set; }
public bool Approved { get; set; }
public DateTime ApprovedDate { get; set; }
public int ApprovedUserId { get; set; }
}
//This is my Faculty Class, which is also Derived from Person
public class Faculty : Person
{
public DateTime HiredDate { get; set; }
public bool Approved { get; set; }
public DateTime ApprovedDate { get; set; }
public int ApprovedUserId { get; set; }
}
我想做的是 Approved、ApprovedDate 和 ApprovedUserId 也很常见。我想指定这些属性,例如:
public class Approve {
public bool Approved { get; set; }
public DateTime ApprovedDate { get; set; }
public int ApprovedUserId { get; set; }
}
并且,想像这样使用:
public class Student : Person, Approve
{
public DateTime DateOfBirth { get; set; }
public DateTime EnrollmentDate { get; set; }
public string Remarks { get; set; }
}
而且,我不能把这些东西放在PERSON里面。因为,我必须将它用于另一个类,但那些不是Person。
那么,我该如何实现这一目标......
请给我一个上述情况的例子。
请帮忙。而且,非常感谢您提前。