File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes [UML] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "[UML]" Watch "[UML]" New topic


dav mrazek
Ranch Hand

Joined: Aug 11, 2007
Posts: 69
Hello i would like to have some advice. I m trying to learn UML modelling and i would like to model my application.
I have two class diagram, User and AdressBook, and i made a composition link from User to AdressBook as all user contain an adressbook instanciated within the constructor, and i made an association link from AdressBook to User. My adressbook contains a collection of User.
- Is it alright to have two different links between two classes ?
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

Yes, it's alright to have more than one link between two classes.
Your first association means: 'has a' (user has address book)
And if you read it in the other direction: 'owned by' (address book is owned by user).

Your second association means 'lists' (address book lists user)
And in the other direction 'listed in' (user is listed in address book).

Regards, Jan
[ August 14, 2007: Message edited by: Jan Cumps ]

OCUP UML fundamental and ITIL foundation
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

It would be interesting to know more about the context (at least, just because an �address book� probably would be composed of �address�)
You have many options:
If the relationship is ONLY between users, a self referencing association would be enough.
Something like (in UML ascii ):

If the addressBook could be used by other objects, you will need a separate address book class.
If is really an address book or contact information you can extract that information from the user class into a address/contact info class:

At low level design/ implementation level, circular dependencies between classes (A depends on B and B depends on A) are harder maintain and usually avoided.
Bottom line: depends on what are you trying to do

Software Surgeon
dav mrazek
Ranch Hand

Joined: Aug 11, 2007
Posts: 69
Hello people, thank you for your answers which help me in doing my model.
so i have my model which translate this way in logical database model :


those will be my tables in my database. Is it a good model ?
Thank you for any improvements, advices, help.
[ August 19, 2007: Message edited by: d dddd ]
dav mrazek
Ranch Hand

Joined: Aug 11, 2007
Posts: 69
Sorry i made some mistakes in my previous post.
For my database i have a table user with id_user as PK, a table contact who is a user with PK compose of, 2 foreign key, id_user from the user who add this contact and id_contact which is the id_user of the contact.
A table addressbook. I need help for this table as i dont really know how this table should be related to user and contact in terms of primary key and foreign key.
Can someone help ?
Thank you.
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

Again, depends...
Are you planning to have any extra information about the addressbook itself (or the user can have more than one)?
If no, you don't need the actual addressbook table, you have:
(this will be equivalent to the first "UML" diagram I posted)
select id_contact
from contact
where id_user = parm_user_id

If you need a separate addressbook, you need to change your model:


As any good OO practitioner would say, the difficulty you have with the relationships of addressbook is because you still need to refine the concept of what do you want to represent.

(And, by no means I'm implying I'm a good OO practitioner! )
dav mrazek
Ranch Hand

Joined: Aug 11, 2007
Posts: 69
Hello and thank you for your reply. I actually dont need to have this adressbook represented as a table, but i thought it would be good to have it. And in my case having the table adressbook makes things more complicated. So i'll make it simple by just having a user table and a contact table.
Is dao design pattern the best way to implement a crud application ? Is there any other design pattern for this ? dao pattern is part of J2EE design pattern, is it ok to use it for other application like a swing application ?
Thank you .
I agree. Here's the link:
subject: [UML]
It's not a secret anymore!