|
| Total Answers and Comments: 3 |
Last Update: October 01, 2008 Asked by: Pritesh Dubey |
|
| | |
|
Submitted by: Dusan B Difference between association and aggregation (while programming implementation for both):
the main difference is conceptual - Aggregation says that an object is made up of other objects, and association says that they have a relationship, they know of each other, or they use each other in some way.
As far as programming, the main difference is in the multiplicities. Aggregation parent can have * and any subset of multiplicities here, but the child making up the aggregation can only have one parent.
This is different from association where you can have any number of possible relationships, going from 1-1, all the way up to *-*.
To clarify, when implementing aggregation Car and Tire, the Car has an aggregation to Tire, and the car has between 4-5 Tire (as an example, one is spare in the trunk) but in no case can a tire belong to two cars at the same time.
So when implementing the Car, you have to check that it has at least 4 and no more than 5 tires, and when implementing the Tire, you have to at all times have a reference to the Car (which means passing the Car reference in the constructor). Furthermore, when the Car reference is set to null, you have to pro grammatically make sure that the Tire references are also set to null in case of Aggregation but if u model your system as Car just having an association to Tire, this might not necessarily be true.
Above answer was rated as good by the following members: dasarishiva | Go To Top
|