The way I normally aproach this is to create an enum with a member for each type and an abstract class that has this type set in the constructor. Often the interface can be removed and the properties etc placed in the abstract class, but if not the abstract class can implement the interface.
Something like:
enum StudentType
{
Graduate,
Current
}
interface IStudent
{
int StudentID { get; set; }
}
abstract class StudentBase : IStudent
{
private StudentType studentType;
private int studentID;
internal StudentBase(StudentType studentType)
{
this.studentType = studentType;
}
public virtual int StudentID
{
get { return studentID; }
set { studentID = value; }
}
StudentType StudentType
{
get { return studentType; }
}
}
class GraduateStudent : StudentBase
{
int passingoutYear;
GraduateStudent()
: base(StudentType.Graduate)
{ }
public int PassingoutYear
{
get { return passingoutYear; }
set { passingoutYear = value; }
}
}
class CurrentStudent : StudentBase
{
int enrolmentYear;
CurrentStudent()
: base(StudentType.Current)
{ }
public int EnrolmentYear
{
get { return enrolmentYear; }
set { enrolmentYear = value; }
}
}
[Added]
AllStudents
would need to be a collection of
StudentBase
for example
List<StudentBase>