What is the difference between Aggregation and Composition in terms of object lifetime?

Last updated 5 July 2026

  • Composition: the part's lifetime is bound to the whole, which owns and usually creates it. Destroying the whole destroys the part (an Order and its OrderLines).

  • Aggregation: the part lives independently and can belong to other wholes (a Playlist and its Songs).

  • Quick test: if the parts are meaningless once the whole is gone, it is composition.

  • https://www.gleek.io/blog/aggregation-vs-composition
  • https://www.geeksforgeeks.org/java/association-composition-aggregation-java/
  • https://www.visual-paradigm.com/guide/aggregation-vs-composition-in-uml-2-0-a-complete-guide-to-whole-part-relationships/
  • https://dev.to/adhirajk/inheritance-vs-composition-vs-aggregation-432i
  • https://www.geeksforgeeks.org/java/difference-between-aggregation-and-composition-in-java/
  • https://medium.com/@evellynliena66/composition-and-aggregation-6f43d2aee9f6
All Object-Oriented Programming interview questions