Meaningless Drivel is fun!*
The moose likes OO, Patterns, UML and Refactoring and the fly likes What is a good example of association Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "What is a good example of association" Watch "What is a good example of association" New topic
Author

What is a good example of association

Mohanlal Karamchand
Ranch Hand

Joined: Jan 14, 2003
Posts: 189
as in <pre>
composition
/ \
/ \
/ \
/ \
/ \
aggregation association
</pre>
is it something as simple as
class A{}
class B{
public A a = new A();
}
or is it something deeper than that ?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

A train.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

(my appologies, I'm assuming this thread is going to be moved )
aadhi agathi
Ranch Hand

Joined: Apr 29, 2002
Posts: 263
Originally posted by Mohanlal Karamchand:
as in <pre>
composition
/ \
/ \
/ \
/ \
/ \
aggregation association
</pre>
is it something as simple as
class A{}
class B{
public A a = new A();
}
or is it something deeper than that ?

association
/ \
/ \
/ \
/ \
/ \
aggregation composition
this seems more logical

also check out dependency( Class A calling a method of class B). Please check out the UML version 5. i like it except the word "semantic" [everthing is hiddedn under it]


Aadhi
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
My humble opinion, if the relationship between the two classes is not inheritance not aggregation not dependency, which are relatively easier to decide, then you may well relate the classes as association. For instance, traffic lights and cars, traffic lights conduct cars, association. Street traffic system aggregates both of the traffic lights class and cars class ( and many more ).
Does that make sense?

Regards,
Ellen
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I'm going to move this to the OO forum, as this discussion is far too meaningful for MD.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Mohanlal Karamchand:
as in <pre>
composition
/ \
/ \
/ \
/ \
/ \
aggregation association
</pre>

Sorry, I don't think I do understand this diagram...

is it something as simple as
class A{}
class B{
public A a = new A();
}
or is it something deeper than that ?

This may well be a valid implementation of an association relationship between B and A (it may also be an aggregation or even composition - it can't be decided from this code snippet).
The semantic of an association from B to A is that instances of B may send messages to (call methods of) instances of class A.
Notice that for this, B doesn't need to have a field of type A. This may change in UML 2.0.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Sahir Shibley
Ranch Hand

Joined: Apr 08, 2000
Posts: 275
I think he means that aggregation and association are two kinds of Composition.
Mr. Karamchand,
I noticed that this thread was moved here from MD.
What is the objective of this question ?
And why are you using a fake name in the OOP forum ?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Sahir Shibley:
I think he means that aggregation and association are two kinds of Composition.

Then he is wrong - composition is a special kind of aggregation, which is a special kind of an association.
Sahir Shibley
Ranch Hand

Joined: Apr 08, 2000
Posts: 275
He seems to have been influenced by Kafura.
http://people.cs.vt.edu/~kafura/cs2704/aggregation.concept.html
Kafura goes on to say "An association among objects is created when an object contains references or pointers to other objects."
That statement seems to imply that association is a relationship between the class and it's public data member ???
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Sahir Shibley:
He seems to have been influenced by Kafura.
http://people.cs.vt.edu/~kafura/cs2704/aggregation.concept.html

Uh oh - what a mess...
http://ootips.org/uml-hasa.html has it right, IMO.

Kafura goes on to say "An association among objects is created when an object contains references or pointers to other objects."

That's bogus - there are no associations between objects, only links (which are instances of associations). I think the reference above explains very well what an association is.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: What is a good example of association
 
Similar Threads
Association or Not
WA #1.....word association
n-ary association
Simple aggregation & association question
Association Classes