File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Aggregation vs Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Aggregation vs Composition" Watch "Aggregation vs Composition" New topic

Aggregation vs Composition

Ahetuki Neti

Joined: May 29, 2003
Posts: 20
What is the difference between aggregation and composition?

Ahetuki, the Constant.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Composition is really a strong form of aggregation.
  • Composed objects have only one owner
  • Composed objects cannot exist independent of their owner (components live and die with their owner)
  • Aggregations may form "part of" the aggregate, but may not be essential to it. They also may also exist independent of the aggregate.

  • [ May 30, 2003: Message edited by: Lasse Koskela ]

    Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
    Ilja Preuss

    Joined: Jul 11, 2001
    Posts: 14112
    With other words: Composition adds a responsibility for controlling the lifetime of the part.
    In garbage collected languages like Java, there isn't much use for composition, in fact...

    The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
    I agree. Here's the link:
    subject: Aggregation vs Composition
    It's not a secret anymore!