lesson

Give each component a clear responsibility

1 · Learn

A modular design separates responsibilities such as validating input, calculating a result and saving it. Small functions with clear inputs and outputs can be tested independently. Shared hidden state makes reasoning harder.

Decomposition should follow meaningful responsibilities, not split code randomly into equally sized pieces. Define how components communicate and what happens on failure.

ValidateCalculateSaveReport outcome
Key words and supplied examples.

2 · Worked example

A calculation function should not silently send an email or overwrite a file if its contract promises only a numeric result.

3 · Your turn

Why is a pure calculation function easier to test than one that also changes unrelated files?

Check your answer

Its result depends on explicit inputs and it has fewer hidden side effects to set up or inspect.

4 · Apply your learning

Design function contracts for a small score calculator and identify which component owns persistence.

Adult guidance and safety

Work in an approved local sandbox with invented records and test accounts. Do not access other people's systems or collect real credentials. Practical project evidence is required in addition to these explanations; this is not a specified GCSE Computer Science course.

Practice this lesson

Lesson resources

Browse the available practice activities and worksheets for this lesson.

Open course resources
Exercise preview