?
Solved

Best Way to Manage Multiple objects

Posted on 2007-10-04
11
Medium Priority
?
220 Views
Last Modified: 2010-04-15
I am making an app that is going to work with multiple sets of data.

Im going to use an Class to define what all goes in each set of data, as well as giving methods to work with this data.

If i do not know how many sets of data i am going to be working with, but it could be anywhere from 0 to infinity(ok not really infinite since a computer has a finite number of resources, but i dont know how many sets of data im going to be working with). What is the best way to store all the sets? Would i be better off using one object with the fields being an ArrayList, or would i be better off making a field in my main WinForm that is an Array that will hold multiple objects of the data Class?

Is there a better way then either of these 2?

Thanks
Donald
0
Comment
Question by:dstufft
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20014125
You could use a generic List or use a dictionary

By using a dictionary you could supply a key and get the equivalent object
0
 
LVL 4

Assisted Solution

by:smitcham
smitcham earned 200 total points
ID: 20014294
This is a larger issue that simply whether to choose a list or a single object.

First, you are correct in encapsulating your data into a class that can be used.  Next you need to determine whether you will need to see multiple instance of the class at the same time.  If that is the case, then a list of all the objects is needed along with some other mapping to what the 'active' data instances are.

Finally,  you need to set up your view in such a way that you can change out the data object being displayed without having side-effects into previously viewed data objects.  There are a lot of web pages out there with tutorials on databinding.
0
 
LVL 7

Accepted Solution

by:
joesthebighmoe earned 1000 total points
ID: 20014478
<<Im going to use an Class to define what all goes in each set of data, as well as giving methods to work with this data.>>
Sounds like a decision leading you towards business-objects.
http://en.wikipedia.org/wiki/Business_object_(computer_science)

Following a business-object-oriented approach you might create a second object that contains a collection of these objects. This new object would expose methods that would operate on all the objects it contains. At this point it does not matter what kind of .Net collection you use because you would hide the implementation behind the scenes and could change it when ever a situation dictated you do so.

For example I might have a business object called ApartmentListing with 5 properties and 3 methods. I might then have a second object called ApartmentListings that contains a generic Queue class that is holding on to the 2000 Listings.  The end result is a de-spaghetti-fied user interface that can care less whether the collection of Apartment Listings are in an ArrayList, Dictionary, or Xml Document.  

My point is that if I am right in my assumption that you are sliding towards a business-object-oriented design, then just build your business object that holds a collection and concentrate on the business of the collection...its methods and attributes that help you get your work done. Later you can tweak whatever collection you use behind the scenes based on some future performance issue or maybe comfort level with some new collection etc.

Cheers,
Joe
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:JimBrandley
ID: 20014788
Donald - Can you describe the content of these sets of data? I think we might be able to give you a better fit for your specific needs with a bit more information about the problem.

Jim
0
 

Author Comment

by:dstufft
ID: 20014983
I'm looking at the solutions already suggested. The Data i am specifically talking about is going to be Account information for logging into an online game. A Basic Listing of What will be required is...

First Name
Last Name
Password
Master-ID (this is a UUID of the account that is allowed to control this account)

Basically this whole program is going to log into the game and allow some remote control via the Private Message function in the game. The Class in question i was planning on using to store the data related to each individual account. The program will need to be able to hold multiple instances of this class because it will need to be able to hold multiple accounts.
0
 

Author Comment

by:dstufft
ID: 20014997
Sorry,

Forgot to add, i am researching the solutions currently suggested but i am still wide open to any other suggestions.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20015040
Arent you using a database to save these records?
0
 
LVL 22

Assisted Solution

by:JimBrandley
JimBrandley earned 400 total points
ID: 20015043
I think then that you need two class for this part of it. One possibly called Gamer, the other is just a collection of them. Say List<Gamer> Players.

Jim
0
 

Author Comment

by:dstufft
ID: 20015071
"Arent you using a database to save these records?"
     My Plan is to Try and Use a Local Database to save the records yes, however i was thinking (and i may be wrong) that i would want to use the Classes to hold the data during runtime, then have a "Save" method that processes the objects and saves them to the dbase.
0
 
LVL 21

Assisted Solution

by:surajguptha
surajguptha earned 400 total points
ID: 20015087
Then the idea of using a List<YourClass> is the best option for storing the data untill a save.
0
 

Author Comment

by:dstufft
ID: 20015301
Thanks for all your help, it looks like i'm going to make a class that will have an instance for each record, then will have another class that will have one instance that will contain all the instances of the primary class.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question