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 / General / January 2007

Tip: Looking for answers? Try searching our database.

How to understand two classes mutual "has a" relationship?

Thread view: 
Shawn - 05 Jan 2007 01:25 GMT
Hi,

I saw a UML diagram showing two classes A and B. A "has a" B in it. B
"has a" A in it. I feel hard to understand.

Could you help me or give me some code to show that concept?

Thank you very much.
Chris - 05 Jan 2007 02:12 GMT
> Hi,
>
[quoted text clipped - 4 lines]
>
> Thank you very much.

class A {
  private B b;

  public B getB() {
    return b;
  }
}

class B {
  private A a;

  public A getA() {
    return a;
  }
}

Pretty simple.
Eric Sosman - 05 Jan 2007 04:26 GMT
> Hi,
>
> I saw a UML diagram showing two classes A and B. A "has a" B in it. B
> "has a" A in it. I feel hard to understand.
>
> Could you help me or give me some code to show that concept?

    The thing to remember is that "has a" really means
"has a reference to a."

    You give your friend a piece of paper with your telephone
number, and she gives you a piece of paper with hers.  Neither
of you has swallowed the other, and there's no crazy infinite
recursion of mutual swallowing: Each of you walks away with
piece of paper, and each has the ability to call the other.

Signature

Eric Sosman
esosman@acm-dot-org.invalid



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.