GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Concepts  >  UML
Go To First  |  Previous Question  |  Next Question 
 UML  |  Question 11 of 18    Print  
How to identify strong aggregation (composition) relationship between classes and what is difference between association and aggregation(while programming implementation of them)?

  
Total Answers and Comments: 3 Last Update: October 01, 2008     Asked by: Pritesh Dubey 
  
 Sponsored Links

 
 Best Rated Answer
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
April 20, 2007 07:09:29   #1  
rashmitambe Member Since: April 2007   Contribution: 3    

RE: how to identify strong aggregation (composition) r...
In strong aggregation or composition a part entity cannot exist without the containing whole entity in 'whole-part' relationship.
For example. an university has multiple department. This a composition relationship between university and department entity. A department cannot exist on its own with out the university.


 
Is this answer useful? Yes | No
November 02, 2007 12:09:26   #2  
Dusan B        

RE: how to identify strong aggregation (composition) r...
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.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
September 30, 2008 21:28:56   #3  
jherna Member Since: September 2008   Contribution: 1    

RE: how to identify strong aggregation (composition) relationship between classes and what is difference between association and aggregation(while programming implementation of them)?
First let me say that aggregation is not composition or viseversa. The OOD concept is "Association" and there are two types. Both are "Has a" relationships. One is "Aggregation" (a strong "Has a") and the other is "Composition" (a weak "Has a").

AGGREGATION EXAMPLE:
A Person class is an the "aggregating" class and the Person object "has a" heart from the Heart class which is the "component" class. When the Person class object is collected by garbage collection so does the Heart class object associated with that Person class object.

COMPOSITION EXAMPLE:
An Engine class is an the "aggregating" class and the Engine object "has a" carbuator from the Carbuator class which is the "component" class. When the Engine class object is collected by garbage collection the Carbuator class object associated with that Engine class object does not go to the salvage yard. It can go to another Engine object.

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape