aimnova.
DashboardMy LearningPaper MasteryStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aimnova.

AI-powered study platform for smarter revision, past-paper analysis and examiner-style feedback.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.8afc4e3

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer Science HLTopic 7.2Composition and aggregation
Back to Computer Science HL Topics
7.2.44 min read

Composition and aggregation (Computer Science HL)

IB Computer Science • Unit 7

AI-powered feedback

Stop guessing — know where you lost marks

Get instant, examiner-style feedback on every answer. See exactly how to improve and what the markscheme expects.

Try It Free

Contents

  • Built from parts, not descended from them
  • In code
  • Why prefer it to inheritance
  • Exam-style question
The big idea: Composition and aggregation are both has-a: one object holds another as an attribute.

The difference is ownership — whether the part can survive without the whole.
CompositionAggregation
RelationshipOwns — part ofUses — has a reference to
Part survives the whole?No — destroyed with itYes — exists independently
ExampleA House and its RoomsA Course and its Students
CreatedUsually by the whole, inside itPassed in from outside
UMLFilled diamond ◆Hollow diamond ◇
The survival test: Delete the whole. Does the part still make sense on its own?

Delete a house — its rooms are meaningless, so that is composition. Delete a course — its students still exist and are enrolled elsewhere, so that is aggregation.

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime

The tell in the code

  • The whole constructs the part inside itself → composition
  • The part is passed in as a parameter → aggregation
  • Composition: nothing outside holds a reference to the part
  • Aggregation: the part is referenced elsewhere too, and must not be destroyed

Stop wasting time on topics you know

Our AI identifies your weak areas and focuses your study time where it matters. No more overstudying easy topics.

Try Smart Study FreeYour first topic is free to keep • No credit card required

Looser coupling

  • The whole depends on the part's interface, not its internals
  • Changing the part's implementation breaks nothing
  • Inheritance exposes the parent's internals to every child

Changeable at run time

  • A part can be swapped while the program runs
  • A superclass is fixed the moment the object is created
  • So behaviour can be reconfigured rather than recompiled

No inherited baggage

  • You get only what you asked for
  • Inheritance brings everything the parent has, wanted or not
  • Including members that make no sense on the child
Prefer composition over inheritance: The standard advice, and the reason is the is-a test: inheritance is right only when the child genuinely is a kind of the parent.

When it is reached for merely to reuse code, composition does the same job with far less coupling.

How this is tested — you must classify a relationship using ownership, and justify composition against inheritance. It comes up two ways:

Paper 2 — working with code

  • Explain composition and aggregation, 3-4 marks
  • Classify a given pair of classes
  • State which UML diamond applies

Paper 2 — the algorithmic-thinking question

  • Design classes for a scenario and justify the relationships
  • Explain why inheritance would be wrong
The classic trap: Treating any has-a as composition. The distinction is ownership: if the part survives the whole being deleted, it is aggregation. Apply the survival test explicitly.
IB-style questionExplain[5 marks]

A school system has Department, Teacher and Classroom. Explain which relationships are composition and which aggregation, justifying each.

Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Composition and aggregation. Write your answer and get instant AI feedback — just like a real IB examiner.

A ferry operator's Sailing class holds an array of Booking objects, and a Booking's fare is set by the Sailing when the booking is made — a Booking cannot exist without its Sailing. the relationship between the Booking and Sailing classes. [2 marks]

Related Computer Science HL Topics

Continue learning with these related topics from the same unit:

7.1.1Fundamentals of OOP
7.1.2Designing classes
7.1.3Static vs non-static
7.1.4Classes and objects
View all Computer Science HL topics

Improve your exam technique

Command terms, paper structure, and mark-scheme tips for Computer Science HL

Previous
7.2.3Abstraction
Next
Design patterns7.2.5

1 practice questions on Composition and aggregation

Students who practiced this topic on Aimnova scored 82% on average. Try free practice questions and get instant AI feedback.

Try 1 Free QuestionsView All Computer Science HL Topics