wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What does a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What does a "one to many" relationship mean" Watch "What does a "one to many" relationship mean" New topic
Author

What does a "one to many" relationship mean

Wilson Mui
Ranch Hand

Joined: Apr 09, 2003
Posts: 140
I'm doing some practice exams and I came across that term, I thought "One to Many" meant one class (B) having another class (A) as a field.
so that the B would have a "One to Many" relationship to A. Because one "B" can have many "A"s But that was wrong, so now i'm trying to figure out what this means.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Let�s suppose only one program at a time can open a file for write access, but any number of programs can open a file for read access.
The write-access relationship between Program and File is 1-to-many. A program can open many files for write access, but a file can have only one opener.
The read-access relationship between Program and File is many-to-many. One program can open many files for read access, and a file can have many openers.
[ April 18, 2003: Message edited by: Marlene Miller ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391

[ April 18, 2003: Message edited by: Marlene Miller ]
Badri Sarma
Ranch Hand

Joined: Apr 01, 2003
Posts: 72
And i think Object class has one to many relationship with other classes, because it is the parent class for all the java classes and Object class can refer to any class in java.


Thanks<br />Badri
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Wilson
What does a "one to many" relationship mean?
First,it is related to Object Oriented model for UML diagram.
We assume that we have two class,one is animal class,another is Moose.
Now we can not see anyone property(For example, tail) in animal that can identify it is The Moose,it may be the dog or any other animal that has tail.Is it right?
And then,we all know that Moose Property can identify it is animal.
So, the animal class has one to many relationship to which belong to animal (or in this example,Moose.
I hope that I can explain clear in this situation.


Francis Siu
SCJP, MCDBA
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
In a class diagram, multiplicities are applied to the association relationship not the inheritance relationship.
Suppose you have two classes Mailbox and Message. Neither is a subclass of the other. There is no inheritance relationship. But there might be an association �mailbox contains message�.
The �contains� relationship is one-to-many. One Mailbox *object* contains many Message *objects* and one Message *object* is contained in only one Mailbox *object*.
[ April 19, 2003: Message edited by: Marlene Miller ]
Francis Siu
Ranch Hand

Joined: Jan 04, 2003
Posts: 867
hi Marlene

The �contains� relationship is one-to-many. One Mailbox *object* contains many Message *objects* and one Message *object* is contained in only one Mailbox *object*.

humm..
you should point out the property of mail address in this case because it is primary key if and only if one person live in this flat.

In a class diagram, multiplicities are applied to the association relationship not the inheritance relationship

I total agree above statement that I am not talking about inheritance relationship in the previous example,although the example contains it
thanks
 
 
subject: What does a "one to many" relationship mean
 
Similar Threads
IS-A & HAS-A Relationship
question from sun
Relevance Of Unique Attribute In Many-To-One relationship
Hibernate and Javassist
Entity Relationships - Many-to-Many mapping ?