Lesley's Digital Garden

Home

❯

Notes

❯

aggregation vs composition

aggregation vs composition

Mar 14, 2024

  • computing/OOP
  • computing/SoftwareEngineering

In the UML diagram, there is a distinction between aggregation and composition. In most garbage collected programming languages, there are no difference in code between them. However, composition implies ownership while aggregation does not.

struct Composition {
  T1 v1;
  std::unique_ptr<T2> v2;
};
 
struct Aggregation {
  T* v = nullptr; // non-owning
};

References

  • Difference Between Aggregation and Composition in UML

Graph View

Backlinks

  • value-oriented programming

Created with Quartz v4.5.2 © 2026. All notes are written in Obsidian.

  • GitHub Repository
  • Mastodon