TMan
TMan

Reputation: 4122

Using enum correctly or not

I'm trying to set up some database tables and create some model classes for the subject of Teacher, Student, Courses, Semester. This is for a MVC3 Web App. If I have a userprofile entity and model class. Would it work if I created a classification enum in the userprofile modelclass and that enum would be either Teacher or Student. Idk If this could work. I don't really know how I can do this b/c I'm going to need the courses that the student is enrolled in and for a teacher, I would need the courses that he/she is teaching and taught. Any advice would be much appreciated.

So for example maybe something like this in the userprofile class:

    class UserProfile {

         public Guid UserID { get; set; }
         public string fname { get; set; }
         public string lname { get; set; }
         public Classification classification { get; set; }

     }

    public enum Classification {

        Student, Teacher
    }

Upvotes: 0

Views: 187

Answers (2)

SLaks
SLaks

Reputation: 887413

Your situation is tailor-made for derived type.

UserProfile should be abstract, with two concrete types called Teacher and Student.
These inherited types can then each have different properties.

Upvotes: 5

Matt T
Matt T

Reputation: 511

Your design looks good to me.

You could also use a boolean variable, for instance UserIsPatient or UserIsTeacher, but by using an enumeration you've created something that can be easily expanded if your requirements change later - for instance, if you wanted to add student teachers, interns, or whatever.

Upvotes: 1

Related Questions