Save objects to disk or save Vector of objects ?
I suppose this question applies to many different situations, but in this case 'm building and Addressbook. I save all the adresses individually in little *.add files. When the program opens these files are then (ObjectInputStream) placed in a Vector which is placed in a JList.
Now this works fine, but would it be better and/or easier to save the Vector to the disk, or maybe even the JList? (if you can do that with a JList, i presume you can).
My thought is that in connection with sorting the list, it might be easier to save a Vector, since it then would be sorted beforehand next time you open it.
But is this the only difference between the two approaches?
No, another difference is that when you change an address, you either have to save the single .add file that was affected or you have to save the entire Vector of addresses. And a similar difference occurs when you add or remove an address. And no doubt there are other differences.
yeah - serialization is carp :-/ (slow, inefficient, and awkward)
rob,
> And if one add file becomes corrupted then you loose
> that single entry. With one file for the vector you
> loose everything.
>
> If you are just mucking around maybe you should
> consider venturing in the wonderful world of
> databases.
I did this a couple of times and my conclusion was that using serialization for keeping stuff like this is primarily a convenience issue. Creating a .add file with a serialized object doesn't take much thought and the I/O code is already written. In my experience though the cost of versionUID mismatches and the like make it much more reasonable to simply use DataInputStream and DataOutputStream so that you have maximum flexibility in the future.
Databases are nice but I would never use a mail client for example if it requred me to install Oracle. Maybe if you used PointBase or InstantDB you could get the niceties of a DB without having a separate app.
I would definitely not serialize an entire vector though, talk about trouble!
quote:
> In my experience though the cost of versionUID mismatches
> and the like make it much more reasonable to simply
> use DataInputStream and DataOutputStream so that you
> have maximum flexibility in the future.
why is this more flexible?
because you do not have to cast the Object to an Address Object?