> Hi,
>
[quoted text clipped - 19 lines]
>
> Shaun
Shaun,
If you haven't already, I would suggest you start by reading this:
http://www.w3.org/TR/vcard-rdf
In my opinion, your program would be made more valuable by conforming to
standards, enabling interoperability with other programs. For instance,
maybe someone would like to share the contacts from your program with
their cell phone or PDA.
Also, you may want to reconsider having your Contact class include
methods to read write the XML. IMO, this should be done at a higher
level. The XML output is not really a function of a Contact object, and
there is no reason for a Contact to know anything about XML. You may
want to consider something like:
(ContactList) contactList.addContact(Contact c);
contactList.saveContactList(ContactList cl);
or have a dedicated XmlWriter class which accepts the contactList as a
parameter, depending on the internal format of the contactList.
Something like a ContactList class will also be helpful in organizing
the list of contacts (indexing, searching, sorting, etc.)
HTH,
Carl.
Mario Winterer - 12 Aug 2005 13:56 GMT
Hi Shoun/Carl!
I agree with Carl - the Contact class should not know anything about persistance.
Instead better introduce something like an AddressBook (or call it ContactList as Carl suggested).
I think neither the AddressBook should know how to load or store contacts!
Better shift the code that does persistance issues (load/save/delete an AddressBook) to a separate component/class (e.g.
AddressBookStorage).
Design this Storage component as java interface that defines just the methods that are required to save, load and delete the
addressbook.
Then implement this interface. If you do not want to mess around with DOM for the first version of your application, you can use the
java serialization mechanism and write a SerializationAdressBookstorage first. Continue with more complex storages (e.g. write an
XMLAddressBookStorage that manages adresses in an XML file or an VCardAddressBookStorage for managing contacts in the vCard file
format - the latter might be just for exporting/importing contacts).
Since Java 1.4, two classes that might help you storing/reading XML files exist: java.beans.XMLDecoder and java.beans.XMLEncoder.
They are easier to use than DOM - but the output XML format cannot be chosen.
Another thing: You Contact class just represents one single contact/person. Do not include linkage information to other contact
objects in this class!
This is part of the AddressBook object! (see Carl's code snippet below).
So the Iterable interface should be implemented by AddressBook - not Contact.
Best regards and have fun with Java,
Tex
>> Hi,
>>
[quoted text clipped - 41 lines]
> HTH,
> Carl.
shaun - 12 Aug 2005 14:28 GMT
Hi Tex,
Thanks for your reply, just one question - why would AddressBookStorage
be defined as an interface and then implemented? And which class should
this be implemented in?
Thanks again for the advice
Shaun
Oliver Wong - 12 Aug 2005 21:00 GMT
> Hi Tex,
>
> Thanks for your reply, just one question - why would AddressBookStorage
> be defined as an interface and then implemented?
Make it an interface so that multiple classes could implement it.
Right now you've only got plans for one class to implement it (some sort
of XML reader/writer), but later on you might want to also implement a
plaintext reader/writer or an Microsoft Outlook PST reader/writer.
> And which class should this be implemented in?
Make a new class to implement it.
- Oliver