Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Custom Object that has 'nested' collections

Custom Object that has 'nested' collections

Scheduled Pinned Locked Moved C#
questioncomhelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kloepper
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • K kloepper

      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

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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; }

      K 1 Reply Last reply
      0
      • G Guffa

        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; }

        K Offline
        K Offline
        kloepper
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • K kloepper

          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

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          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; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups