Composition and aggregation
Practice Flashcards
Flip to reveal answersComposition or aggregation — what is the difference?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All 5 Flashcards — Composition and aggregation
Sign up free to track progress and get spaced-repetition review schedules.
Question
Composition or aggregation — what is the difference?
Answer
Both are has-a. **Composition** owns the part, which dies with the whole. **Aggregation** references a part that exists independently.
Question
What is the survival test?
Answer
Delete the whole. If the part still makes sense it is **aggregation**; if it is meaningless it is **composition**.
Question
What is the tell in code?
Answer
The whole **creating** the part inside itself → composition. The part **passed in** → aggregation.
Question
Which UML diamond means composition?
Answer
The **filled** diamond ◆. A hollow diamond ◇ means aggregation.
Question
Why prefer composition over inheritance?
Answer
Looser coupling (interface, not internals), parts swappable at run time, and none of the parent's unwanted members.
Read the notes
Full study notes for Composition and aggregation
Topic 7.2 hub
OOP: multiple classes
More from Topic 7.2
All flashcards in this topic
Computer Science exam skills
Paper structures & tips
Track your progress with spaced repetition
Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.
Start Free