I'm having trouble searching for what I'm trying to figure out, so please forgive my ignorance here. I build a small business application using VB about once per year and I just don't know the words I should be searching for my new problem.
I am hoping someone can suggest the appropriate objects, containers, collections, lists, or whatever I should be using to accomplish this. I can do the research on how to use them, I just don't know what will help me do this.
I am creating a simple VB game for fun and my kids using VB.NET Express 2013. I want to create an object that can have a variable number of "sub-objects". And each sub-object may have sub-objects. Here's what I mean:
1. Master House object (Length, Width, Height variables; AddRoom method)
2. The House object may also contain Room objects. There could be any number of Rooms in the House...1, 2, 3...10. (Each room has it's own L,W,H; and an AddComputer method)
3. Each Room object may contain Bookshelf objects. Any number of Bookshelves per room. (Each Bookshelf has it's own Size, Color, etc.; and an AddBook method)
4. Each Bookshelf may contain any number of Books.
So based on this, here are my thoughts. Feel free to tell me how my thinking is wrong on this.
1. In a business app, I would just store this info in the DB with the appropriate keys and would generally only access info for a small dataset at a time, so speed isn't an issue. If I want to have 100 Houses on the screen for instance, with quick access to the details inside each House on a mouseover, pulling from the DB each time seems inefficient.
So it seems that loading this info into memory is a better way to go. Am I right on this?
2. I've tried using List. This worked well for 2 levels when I could create the House and add Rooms to it. But once I was trying to create a new House, the Rooms in it, and the Bookshelves per room, I got a little lost. The code to add an object got so long and unwieldy it was ridiculous.
I couldn't help but think I wasn't handling it correctly. There must be a better way. Is there a container or collection that's made to handle this sort of thing?
I am hoping someone can suggest the appropriate objects, containers, collections, lists, or whatever I should be using to accomplish this. I can do the research on how to use them, I just don't know what will help me do this.
I am creating a simple VB game for fun and my kids using VB.NET Express 2013. I want to create an object that can have a variable number of "sub-objects". And each sub-object may have sub-objects. Here's what I mean:
1. Master House object (Length, Width, Height variables; AddRoom method)
2. The House object may also contain Room objects. There could be any number of Rooms in the House...1, 2, 3...10. (Each room has it's own L,W,H; and an AddComputer method)
3. Each Room object may contain Bookshelf objects. Any number of Bookshelves per room. (Each Bookshelf has it's own Size, Color, etc.; and an AddBook method)
4. Each Bookshelf may contain any number of Books.
So based on this, here are my thoughts. Feel free to tell me how my thinking is wrong on this.
1. In a business app, I would just store this info in the DB with the appropriate keys and would generally only access info for a small dataset at a time, so speed isn't an issue. If I want to have 100 Houses on the screen for instance, with quick access to the details inside each House on a mouseover, pulling from the DB each time seems inefficient.
So it seems that loading this info into memory is a better way to go. Am I right on this?
2. I've tried using List. This worked well for 2 levels when I could create the House and add Rooms to it. But once I was trying to create a new House, the Rooms in it, and the Bookshelves per room, I got a little lost. The code to add an object got so long and unwieldy it was ridiculous.
I couldn't help but think I wasn't handling it correctly. There must be a better way. Is there a container or collection that's made to handle this sort of thing?