Difference between composition and aggregation



Composition and aggregation are two types of association which is used to represent relationships between two classes. 

In Aggregation , parent and child entity maintain Has-A relationship but both can also exist independently. We can use parent and child entity independently. Any modification in the parent entity will not impact the child entity or vice versa. In the UML diagram, aggregation is denoted by an empty diamond, which shows their obvious difference in terms of strength of the relationship.

In Composition, parent owns child entity so child entity can’t exist without parent entity. We can’t directly or independently access child entity. In the UML diagram, composition is denoted by a filled diamond. 

Sr. No.KeyCompositionAggregation

1

Basic 

Composition(mixture) is a way to wrap simple objects or data types into a single unit

Aggregation(collection) differs from ordinary composition in that it does not imply ownership

2

Relationship 

In composition , parent entity owns child entity.

In Aggregation , parent Has-A relationship with child entity

3

UML Notation 

It is denoted by a filled diamond. 

It is denoted by an empty diamond. 

4. 

Life cycle 

Child doesn’t have their own life time 

Child can have their own life time 

5.

Association 

It is a strong association 

It is a weak association 


raja
Published on 21-Jan-2020 07:44:28
Advertisements