What is the difference between aggregation and composition in UML?

1 Answers
Answered by suresh

Difference between Aggregation and Composition in UML - Interview Question

What is the difference between Aggregation and Composition in UML?

Aggregation and Composition are two important relationship types in UML that define how one class is connected to another. Here are the key differences between Aggregation and Composition:

Aggregation:

  • Aggregation represents a "has-a" relationship between objects, where one object contains a reference to another object.
  • The objects involved in an aggregation can exist independently from each other.
  • An aggregation relationship is typically shown with a diamond shape on the containing class.

Composition:

  • Composition represents a stronger relationship between objects, where one object is a part of another object and cannot exist without it.
  • The objects involved in a composition are strongly connected and have a lifecycle dependency.
  • A composition relationship is typically shown with a filled diamond shape on the containing class.

It is important to understand the differences between Aggregation and Composition in UML to accurately model the relationships between classes in a software system.

Answer for Question: What is the difference between aggregation and composition in UML?