IB Computer Science HL · Year 2 · Lesson 19

Aggregation vs composition

Multiple-class OOP adds relationships and flexible behaviour through inheritance, polymorphism, abstraction, composition and patterns.

Paper 250 minutesB3.2.4
Today’s targets

What you need to be able to do

2 / 8
  • ExplainThe role of composition and aggregation in class relationships
B3.2.4
Paper 2 lensMatch the depth of every response to the command term. Previously learned content can move quickly, but retrieval must still be accurate.
Retrieve

Rapid Recall Deck

3 / 8

Say the answer aloud before flipping. Mark secure knowledge quickly and spend time on the gaps.

  • What is aggregation in a class relationship?: A 'has-a' relationship where the component object can exist independently of the object that uses or groups it.
  • What is composition in a class relationship?: A stronger 'has-a' relationship where the component is tightly owned and its lifecycle is tied to the containing object.
  • What is the main difference between aggregation and composition?: Aggregated components can exist independently; composed components are considered part of the whole and do not meaningfully exist outside it.
  • Why use composition or aggregation instead of inheritance?: They build larger objects from smaller components without claiming an 'is-a' relationship, often reducing unnecessary coupling.
B3.2.4 · Learn

Core knowledge and application

4 / 8
B3.2.4Explain

The role of composition and aggregation in class relationships

Multiple-class OOP adds relationships and flexible behaviour through inheritance, polymorphism, abstraction, composition and patterns.

Exam moveGive the mechanism or relationship and make the reasons/causes explicit.
Required detail 1How to design objects by leveraging smaller component objects through composition and aggregation
Required detail 2That aggregation implies that the subcomponents can function independently of the aggregating class, while in composition, the subcomponents are tightly coupled and cannot exist outside the aggregating class
Assessment boundaryPaper 2

Explain it without notes

Explain: The role of composition and aggregation in class relationships in the context of a school platform with multiple interacting object types.

  • How to design objects by leveraging smaller component objects through composition and aggregation
  • That aggregation implies that the subcomponents can function independently of the aggregating class, while in composition, the subcomponents are tightly coupled and cannot exist outside the aggregating class
Trace / construct

Programming checkpoint

5 / 8
class Engine:
    def start(self): return "running"
class Car:
    def __init__(self):
        self.engine = Engine()  # composition
Before you run itTrace the code by hand. Identify state changes, branch/loop behaviour, and the final result.

Modify it

Change one condition, input or operation so the program solves a slightly different problem. Predict the effect before editing.

Apply

Transfer to a new scenario

6 / 8
ScenarioA school platform with multiple interacting object types needs a design or technical decision related to today’s topic. Explain what matters and why.
  • How to design objects by leveraging smaller component objects through composition and aggregation
  • That aggregation implies that the subcomponents can function independently of the aggregating class, while in composition, the subcomponents are tightly coupled and cannot exist outside the aggregating class
Exam lens

Paper 2 practice

7 / 8
Build the response before checking notesUse precise terminology and match the required depth.
  1. Explain: The role of composition and aggregation in class relationships in the context of a school platform with multiple interacting object types.
Self-checkAnswer the exact command term. For explain, include mechanism/reason; for compare, pair criteria; for discuss/evaluate/justify, build supported reasoning and a conclusion.
Homework

Finish the learning cycle

8 / 8

IA — main task

Continue Criterion D development. Keep code readable, record meaningful implementation decisions, and maintain testing/evidence notes as you work.

Syllabus — short

Complete one targeted Paper 2/Paper 1 retrieval task from today’s lesson.