I have a user model in an application that I'm working on, which currently uses sub-types to encapsulate properties depending on what type of user you are - I just can't help but think that this is really bad design.
To expand in more detail, a User in our Application can either be an Instructor or a Student, and below is how this is currently modelled:
public class User
{
public string EMail {get; set;}
public string DisplayName {get; set;}
public Student StudentObject {get; set;}
public Instructor InstructorObject {get; set;}
public void Login()
{
//...
}
public void BookAppointment()
{
//...
}
//Other User-Level Behaviours
public class Instructor
{
public TimeSpan TypicalDayStart {get; set;}
public TimeSpan TypicalDayEnd {get; set;}
public ObservaleCollection Students {get; set;}
//No Instructor Specific Behaviour / Methods
}
public class Student
{
public string CurrentGrade {get; set;}
public DateTime NextExamDate {get; set;}
public bool ExamPassed {get; set;}
public int InstructorID {get; set;}
//No Student Specific Behaviour /Methods
}
}
To me, this really smells. But I can't think of a better way to model the data:
- Separate
Instructor/Studentclasses seems to be the wrong way to go, as they're not actually separate entities in their own right, they're just a collection of properties that are unique to the different types of user our application handles. - Removing the sub-types and handling all the data under one class seems to be the way I'm inclined to go. However this makes some
propertiesredundant. It's also not very future-proof... Just because there's no Instructor / Student Specific behaviour at the moment doesn't mean there won't be in the future.
