I am working on a C # application which consists of Department, Course and Section objects. Each department has many courses, and each course has many sections. I currently have three classes: department, course, and section. The department contains some properties, followed by a list of courses that contains the courses offered by the department. The course contains some properties, and then sections of the list that contain sections of the course. Is this a good way to structure my code, or should I do it differently?
Secondly, when I create a department instance in my application, I set some properties and then I would like to start adding courses to the Courses list defined in the Department class. However, I can't seem to just make Department.Courses.Add (course) from the application. What should I do in the department class to add objects to this list without violating the encapsulation principle?
An example of what I have with the list:
class Department
{
List<Course> Courses = new List<Course>;
}
however, in the Code section, the program code is not available after the class has been created (all other class properties are available).
source
share