File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes types of relationships 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 "types of relationships" Watch "types of relationships" New topic
Author

types of relationships

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

what are different types of relationships


Groovy
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Umm, can you clarify the question, please? I can think of so many types of relationships I don't know where to start. Do you have a specific context in mind ?


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I got confsued b/w Association ,dependency and Aggregation
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Association is where one object is associated with another, but either one can exist without the other. Consider a motor vehicle and a driver. A vehicle doesn't have to have a driver, and a driver doesn't have to have a vehicle, but sometimes, a particular driver is associated with a particular vehicle. The driver and the vehicle have an association relationship.
Dependency is when one obect can't be used without another. Consider a motor vehicle and some fuel. The fuel might still be useful without a vehicle, but the vehicle can't do its job without fuel. So the vehicle is dependent on the fuel. The vehicle and the fuel have a dependency relationship.
Aggregation is where one object is composed of others. Consider a motor vehicle and its wheels. The wheels can be stored, sold or fitted individually, but to build a motor vehicle you need a body, wheels, a motor, and so on. Only when you have all these things together can you say that the motor vehicle is usefully complete. The driver doesn't individually control the wheels, he controls the vehicle which manages the wheels for him. The vehicle and the wheels have an aggregation relationship.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I am an important Q -
Can I conclude that when an object uses another object (by invoking some method or accessing some variable) ASSOCIATION relationship is established ?.
Also I think that Aggregation is a more restricted form of Association.
Lemme know if I am right?
Thanks Frank.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Pradeep Bhat:
Can I conclude that when an object uses another object (by invoking some method or accessing some variable) ASSOCIATION relationship is established ?.
Also I think that Aggregation is a more restricted form of Association.
Lemme know if I am right?

Yes, both are right.


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
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Frank Carver:
Aggregation is where one object is composed of others. Consider a motor vehicle and its wheels. The wheels can be stored, sold or fitted individually, but to build a motor vehicle you need a body, wheels, a motor, and so on. Only when you have all these things together can you say that the motor vehicle is usefully complete. The driver doesn't individually control the wheels, he controls the vehicle which manages the wheels for him. The vehicle and the wheels have an aggregation relationship.

The practical implication is that you can't have cyclic aggregations: an object is not allowed to be aggregated with itself, neither directly, nor through other objects.
And then there is Composition, the third form of Association. Composition is adding a lifetime responsibility: an object composed of other objects is responsible for the creation and destruction of its components.
Vikrama Sanjeeva
Ranch Hand

Joined: Sep 02, 2001
Posts: 756
Hi,
Here is the most simple one...

Human--> Hand relationship is Aggregation
i.e Without hand Human is alive.
&
Human--> Heart relationship is Composition
i.e Without heart Human is dead.
Bye,
Viki.


Count the flowers of your garden, NOT the leafs which falls away!
Prepare IBM Exam 340 by joining http://groups.yahoo.com/group/IBM340Exam/
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Vikrama Sanjeeva:
Human--> Hand relationship is Aggregation
i.e Without hand Human is alive.
&
Human--> Heart relationship is Composition
i.e Without heart Human is dead.

I think these examples are misleading.
First, Composition works the other way around: The lifetime of the *part* is dependend on the *whole*. It has nothing to do at all with the lifetime of the whole.
Second, the lifetime of an object is talking about its *existence*. A human without a heart is still a human and continues to exist - it's just likely that its state will rapidly change from "alive" to "dead".
A better example might be a compartment of a company: a company doesn't need to have compartments to exist, but the existence of compartments is strongly bound to that of a company. The company is responsible for creating new or breaking up existing compartments. The company might also hand over responsibility for the lifetime of a compartment to another company, but there is always exactly one company responsible for every compartment (at least for the sake of this example... ).
Does that compute?
[ September 24, 2002: Message edited by: Ilja Preuss ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: types of relationships