in reply to OT: Refreshing Objects
"Ideally, when the list is refreshed, I would just create a new object for each group and store them in my collection. But that would mean that I would lose the information for each group."
elusion, you have to analyze the information you stored in your group list. There are two types of information:
- One type of information you can get from the network, the news group itself, those information can be flushed and updated each time when you refresh from the network.
- Another type of information is clinet specific, for example the last article number you downloaded in each group. Those ones you have to persist them in a way, and make sure they don't get lost, when you refresh the first type of info.
From a OO design point of view, it is not "ideal" to drop the entire list, and recreate it. Why should you drop the entire list, just because a new element joins the list, or an old element gets deleted? Why should you drop the object, when you can simply modify some of its attributes? You have to clearly differentiate the concepts of object and its attributes. You have to clearly differetiate the object and the collection it is in.Your OO code similates the real world, and in the real world,
- You don't drop all existing news groups and recreat them, when a new group get added or an old group get deleted. They just stay the same, they are independent objects, which has no tight relationship with the one gets added/droped.
- You don't drop the group when new articles added to the news group, some of the attributes of the news group changed, but the news group is still the same as before.
In your OO design, you need to create a new object to represent a new newsgroup when it gets created. You might delete an existing object, when the news group it represents got deleted. (Actually, you even probably should not delete it, instead just mark it as inactive, or dead, as you don't want to lose the history. This depends on the nature of your application.) But other news group should not be affected.
"I could hunt down all the groups that have additional information and copy that information over, but I think that would be a lot of work."
This is the right way to go. Go the right way, not the way seems to be easier.
(Update: gave a second thought, I think I probably have misunderstood your idea. I thought you meant to search and modify particular elements, but you probably actually meant to copy the entire collection. Also, I sense that you might stored multiple copies of the same entity. If that's the case, it would be a better idea, to have just one object to represent the entity, and have all places need it to reference it, not to copy it.)
On the other hand, if the collection data structure you used to store your groups is right, I don't see a reason why it would be difficult for you to allocate a certain group (an element of the collection).
"Else I could try to modify my collection by dropping the groups that have been removed and adding the groups the have been added. Is there a better way? "
There are different options, but this is definitely one of the best ways. And I don't see any big problem with it.
I have the feeling that you are avoiding to write a search method for your collection object. This is either because you are lazy ;-) or your data structure is wrong, thus made such a search algorithm not that easy. If it is the second one, look at your collection structure again.
On the other hand, as you are doing OO design, your search method would be something that you only need to implement once, and can be used forever, why should you avoid it?