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 association class and link attribute 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 "association class and link attribute" Watch "association class and link attribute" New topic

association class and link attribute

Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Association b/w two classes A-->B may be implemented as class A holding a reference to object B, in its instance data. Where does the association class come into picture? It is mentioned that if the association has attributes, we go for an association class. If so, is link an instance of an association class? Not clear about these concepts. Can someone please explain with simple examples.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I may be struck by lightning for saying so, but this is very similar to relational database design when we stick attributes on an association table. Say we have people related to people - parents, children, aunts, uncles, etc. If one person has a simple collection of other people, we don't know how they are related. Maybe we make a tiny Relative object that holds a person pointer and a relationship name. Now a person can have a collection of Relatives, and we look at each object to see exactly how they are related.
Man, that example used relationship too many ways. Sorry. But it gets worse. This will be hard to model:

I Am My Own Grandpa
Many, many years ago
When I was twenty three
I got married to a widow
Pretty as could be.
This widow had a grown up daughter
With flowing hair of red,
My father fell in love with her
And soon the two were wed.
This made my dad my son-in-law
And changed my very life.
Now my daughter was my mother,
For she was my father's wife.
To complicate the matters worse
Although it brought me joy,
I soon became the father
Of a bouncing baby boy.
My little baby then became
A brother-in-law to dad,
And so became my uncle,
Though it made me very sad.
For if he was my uncle,
Then that also made him brother
To the widow's grown up daughter,
Who of course was my step-mother.
Father's wife then had a son
Who kept them on the run,
And he became my grandson
For he was my daughter's son.
My wife is now my mother's mother
And it makes me blue.
Because although she is my wife,
She's now my grandma too.
If my wife is my grandmother,
Then I am her grandchild.
And every time I think of it
It simply drives me wild.
For now I have become
The strangest case you ever saw,
As the husband of my grandmother,
I am my own grandpa!
Ray Stevens
[ August 23, 2003: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Thank you Stan. The association relative class example clears the fog for me, but definitely not the lengthy example
I agree. Here's the link:
subject: association class and link attribute
jQuery in Action, 3rd edition