Aggregation

  • Definition: Aggregation is a weak association where the child can exist independently of the parent.
  • Ownership: The parent object can contain or own a collection of child objects, but those child objects can exist independently of the parent.
  • Lifecycle: If the parent object is destroyed, the child objects can continue to exist.

Example: A Library contains Books. If the Library is destroyed, the Books still exist.

classDiagram
    class Library {
        +Book[] books
    }
    class Book {
    }

    Library "1" o-- "0..*" Book : Aggregation
  • In Mermaid Aggregation:
    • Represented by an open diamond (o--).
    • Indicates a “has-a” relationship where the parent can own the child, but the child can exist independently.