Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

types of relationships

 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are different types of relationships
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got confsued b/w Association ,dependency and Aggregation
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 760
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic