0

I have been searching all over the internet and can't seem to find anything that specifically answers my question.

As far as I can tell, a simple association does not imply any form of life dependency.

A Composition is a whole-part relationship where the lives of the two classes are tied. For example, building and room. A room can not be created without a building, and if a building "dies", so does the room, and vice versa. BOTH are dependent on each other.

I do understand that aggregation is a weaker composition. For example, Car and Tires. But does aggregation imply dependence on the whole's side? Can the whole exist without the parts? Also, in aggregation, do the parts only belong to one whole?

I've found conflicting answers...

I have one more question. Can a simple association be a one-to-many relationship? For example, I am designing a prison management system, a PrisonBlock has Guards. If I say a guard is only assigned to one block. Their lives are obviously not dependent on each other. But there IS, however, a whole-part relationship. Or is there!? I'm confused. The way I see it, the Block (whole) has Guards (parts). Is this association or aggregation? And why? What would I have to change for it to become one or the other? Can an association even BE a one-to-many relationship!?

2 Answers2

0
  1. Aggregation is simply Has-a realtionship. In your example, Car should have tires . Because if it is not then that is not a Car. But Tires doesn't need to have car necessarily. Simply it is Has-a relationship.

    2.Association is a relationship between two separate classes which can be of any type say one to one, one to may etc. It joins two entirely separate entities.

    • Aggregation is a special form of association which is a unidirectional one way relationship between classes (or entities)

THink like this:

If your prisonBlock class can exist without Guard class? Or Guard class can exist without your prisonBlock class?

MeshBoy
  • 662
  • 5
  • 9
0

In compostion we create a opject which is defined in that class scope for example

class a:
     b comObject = new b()

while in aggregation shows has a relation which means object has parent child kind of relationship but this do not means that when parent class die child also die because parent just make a deep copy

in case of association we only make a shallow copy and the differences between association and aggregation is that the related object can not have another parent