Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
"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?


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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2023-06-09 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (36 votes). Check out past polls.

    Notices?