"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:

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,

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?


In reply to Re: Refreshing Objects by pg
in thread OT: Refreshing Objects by elusion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.