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
  1. Home
  2. General Programming
  3. C#
  4. Class Stucture Question

Class Stucture Question

Scheduled Pinned Locked Moved C#
questiondata-structures
6 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.
  • J Offline
    J Offline
    jgallen23
    wrote on last edited by
    #1

    I've created a class that needs to have a subclass array of the same class, so basically my class contains an array of itself. Does this make sense? What is the best way to go about doing this? Basically I need to make a heirarchy of these classes that can never end Class  Class1   ClassA   ClassB  Class2 All these classes have the same properties. Thanks, JGA -- modified at 20:49 Monday 24th October, 2005

    C 1 Reply Last reply
    0
    • J jgallen23

      I've created a class that needs to have a subclass array of the same class, so basically my class contains an array of itself. Does this make sense? What is the best way to go about doing this? Basically I need to make a heirarchy of these classes that can never end Class  Class1   ClassA   ClassB  Class2 All these classes have the same properties. Thanks, JGA -- modified at 20:49 Monday 24th October, 2005

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You mean an array of class types ? You can't do this, because Class1 cannot derive from ClassA and ClassB, and if it did, this couldn't work when both classA and classB expose the same methods. The obvious thing would be to create an interface, and impliment it in all of these classes, but your class heirarchy would be flat, you could have one base class at most on each level, and they would all impliment the interface in the same way What are you trying to do ? Christian Graus - Microsoft MVP - C++

      J 1 Reply Last reply
      0
      • C Christian Graus

        You mean an array of class types ? You can't do this, because Class1 cannot derive from ClassA and ClassB, and if it did, this couldn't work when both classA and classB expose the same methods. The obvious thing would be to create an interface, and impliment it in all of these classes, but your class heirarchy would be flat, you could have one base class at most on each level, and they would all impliment the interface in the same way What are you trying to do ? Christian Graus - Microsoft MVP - C++

        J Offline
        J Offline
        jgallen23
        wrote on last edited by
        #3

        I have a todo list heirarchy and each element can have it's own properties (due date, title, priority). so I can have: Class= Title:Version 1 DueDate: 12/01/05 Priority: High SubClass:  Title:Create blah  DueDate: 10/26/05  Priority: High I'm reading from an XML File to get all of the data, the XML format is something like: <TODOLIST> <TASK DUEDATE=10/24/05 TITLE=ASDF PRIORITY=HIGH>  <TASK TITLE=sdfa></TASK> </TASK> Does that make sense at all?

        C 1 Reply Last reply
        0
        • J jgallen23

          I have a todo list heirarchy and each element can have it's own properties (due date, title, priority). so I can have: Class= Title:Version 1 DueDate: 12/01/05 Priority: High SubClass:  Title:Create blah  DueDate: 10/26/05  Priority: High I'm reading from an XML File to get all of the data, the XML format is something like: <TODOLIST> <TASK DUEDATE=10/24/05 TITLE=ASDF PRIORITY=HIGH>  <TASK TITLE=sdfa></TASK> </TASK> Does that make sense at all?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          OK - so there's no reason in the world to create a class heirarchy. All you need to do is create a class ( or a struct, more like it ), that contains a reference to itself as a parent and a collection of items that represents it's children ( so you can iterate in either direction ). So you need one class, like this class myClass { private string title; private DateTime dueDate; private PrioryEnum priority; // Create an enum for this private myClass parent; private ArrayList children; } Then add properties for access as needed. Christian Graus - Microsoft MVP - C++

          J 1 Reply Last reply
          0
          • C Christian Graus

            OK - so there's no reason in the world to create a class heirarchy. All you need to do is create a class ( or a struct, more like it ), that contains a reference to itself as a parent and a collection of items that represents it's children ( so you can iterate in either direction ). So you need one class, like this class myClass { private string title; private DateTime dueDate; private PrioryEnum priority; // Create an enum for this private myClass parent; private ArrayList children; } Then add properties for access as needed. Christian Graus - Microsoft MVP - C++

            J Offline
            J Offline
            jgallen23
            wrote on last edited by
            #5

            do you'd just create an arraylist of class myclass right?

            C 1 Reply Last reply
            0
            • J jgallen23

              do you'd just create an arraylist of class myclass right?

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              jgallen23 wrote:

              do you'd just create an arraylist of class myclass right?

              If you're using VS2005, then yes, you can create an array of a specific type. Otherwise, the arraylist will contain only objects, but yes, it would be an array of the class instances that are the children of the current object. Christian Graus - Microsoft MVP - C++

              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