Class Stucture Question
-
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
-
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
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++
-
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++
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?
-
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?
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++
-
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++
-
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++