Custom Object that has 'nested' collections
-
The problem: I want to allow an administrator (user) to create a list of teachers, each teacher in turn has a list of classes, each class has a list of students. There's an article at http://aspalliance.com/721 that describes making classes for the Student and the StudentList, but I'm wondering how to make classes that are collections of the other classes, ie a ClassList that holds the StudentList class and a TeacherList class that holds the ClassList class. TeacherList-->ClassList-->StudentList-->Student What is the approach to use to make a custom object that could handle this nesting? The article mentioned above has a StudentList Class that inherits from IEnumerable and uses a Hastable to hold the Student objects that are made up of simple data types. I tried making classes in a similar fashion for the ClassList and StudentList collections, but I'm having casting errors, so I'm not sure that this is the correct approach or my implementation is not correct. Anyone have any ideas or suggestions as to how to nest collections like this? or another approach to accomplish the same thing? If you want to see the code I've tried, I can post it. Thanks, Paul
-
The problem: I want to allow an administrator (user) to create a list of teachers, each teacher in turn has a list of classes, each class has a list of students. There's an article at http://aspalliance.com/721 that describes making classes for the Student and the StudentList, but I'm wondering how to make classes that are collections of the other classes, ie a ClassList that holds the StudentList class and a TeacherList class that holds the ClassList class. TeacherList-->ClassList-->StudentList-->Student What is the approach to use to make a custom object that could handle this nesting? The article mentioned above has a StudentList Class that inherits from IEnumerable and uses a Hastable to hold the Student objects that are made up of simple data types. I tried making classes in a similar fashion for the ClassList and StudentList collections, but I'm having casting errors, so I'm not sure that this is the correct approach or my implementation is not correct. Anyone have any ideas or suggestions as to how to nest collections like this? or another approach to accomplish the same thing? If you want to see the code I've tried, I can post it. Thanks, Paul
The design using a HashTable to hold the objects is sound. I would make a TeacherList object that is a list of Teacher objects. The Teacher object would contain a ClassList object that is a list of SchoolClass objects (as Class is obviously not a good name). The SchoolClass object contains a StudentList object, which is a list of Student objects. --- b { font-weight: normal; }
-
The design using a HashTable to hold the objects is sound. I would make a TeacherList object that is a list of Teacher objects. The Teacher object would contain a ClassList object that is a list of SchoolClass objects (as Class is obviously not a good name). The SchoolClass object contains a StudentList object, which is a list of Student objects. --- b { font-weight: normal; }
Guffa: I just got a reply elsewhere that pointed out the same error that you did, ie, that I don't have a teacher or a class object and that I cannot use the list objects in their place. > A TeacherList would not hold a ClassList. > > A TeacherList has 0-n Teacher objects. > A Teacher has 1 ClassList > A ClassList has 0-n Class objects. > A Class has 1 StudentList > A StudentList has 1-n Student objects. I'm working on the solution now. Hopefully, I'll construct it correctly. Thank you, Paul -- modified at 15:49 Tuesday 7th February, 2006
-
Guffa: I just got a reply elsewhere that pointed out the same error that you did, ie, that I don't have a teacher or a class object and that I cannot use the list objects in their place. > A TeacherList would not hold a ClassList. > > A TeacherList has 0-n Teacher objects. > A Teacher has 1 ClassList > A ClassList has 0-n Class objects. > A Class has 1 StudentList > A StudentList has 1-n Student objects. I'm working on the solution now. Hopefully, I'll construct it correctly. Thank you, Paul -- modified at 15:49 Tuesday 7th February, 2006
Well, you could make the TeacherList contain ClassList objects, but then it would hardly be a teacher list, it would just be a ClassList list. A teacher object would probably contain some more information than just the class lists, like the name of the teacher, to start with. --- b { font-weight: normal; }