Can someone help me understand how best to model a composition relationship?
If for instance I have a student whom can have many schedules, I would create roughly:
class Student
{
prop long Pk { get; set; }
prop string Name { get; set; }
prop List<Schedule> Schedules { get; set; }
}
class Schedule
{
prop string Semester { get; set; }
prop List<Course> Courses{ get; set; }
}
Somewhere down the line I may have a Schedule object, and will wish to identify which student it belongs to. I want to be able to write Schedule.Student.Name
, and receive the student's name in return. Do I add a Student property to my Schedule object as well?
My application has been passing a Student Pk to my Schedule object in order to do CRUD functionality. I'm keeping the Student PK as a private variable in order to keep a handle on it if I need it.
As my application becomes more complex, I'm finding it hard to maintain what I've been doing. What are your suggestions for me? What else can I consult (books/links) to get a refresher and better handle on these fundamentals?