Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2005

Tip: Looking for answers? Try searching our database.

Simple Contact Manager Design

Thread view: 
shaun - 11 Aug 2005 19:11 GMT
Hi,

After reading Ivor Hortons Beginning Java 2 book I am about to atempt
my first program - a simple contact manager. This will be a GUI
application that will store contacts for the user in an XML file.
Before I embark on this I wanted to run my class design past the group
for any advice / recommendations:

1. The GUI will have a JList on the left containing the list of
contacts and textfields on the right for adding / editing contacts.

2. There will be an application class that will include the main method
that will build the GUI.

3. There will be a Contact class that will include methods to read /
write to the XML file using DOM.

4. The Contact class will implement the Iterable inerface so that I can
create a linked list of contacts.

Any comments here would be greatly appreciated.

Shaun
Carl - 11 Aug 2005 19:46 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.