BuryComputing
OCR J277 · 2.3.1 Defensive designDefensive Design
🎯 0/6
Step 1

What is defensive design?

Planning ahead so a program still works when users get things wrong.

What if the user gets it wrong?

The user types…
Output
Anticipating misuse: the programmer plans for wrong input before it happens. Misuse can be by accident (a typing mistake) or on purpose (trying to break the program).

Key facts

Defensive design = planning a program so it still works when users make mistakes or misuse it.
Anticipating misuse = thinking ahead about what could go wrong, then planning for it.
MethodWhat it doesExample
Anticipating misuseStops the user breaking or hacking the programInput sanitisation: removes special characters such as quotation marks and semicolons
Input validationChecks the data entered is sensibleRange check, presence check, type check, length check
AuthenticationConfirms who the user isUsername and password, two-factor authentication (2FA)
MaintainabilityMakes the code easy for other programmers to understandComments, meaningful variable names
In the exam: name ONE method, then describe it or give an example.

What else could go wrong?

ActivitySort it: which method?

ActivityWhich method would help?

Step 2

Input validation

Checking the data is sensible before the program uses it.

Types of validation checks

The rule
Try an input

Key facts

Input validation = checking the data entered is sensible, and follows the rules, before it is processed.
If the data is invalid, the program shows an error message and asks for it again.
CheckIt checks that…Example
PresenceSome data has been enteredThe name box is not blank
TypeThe data is the correct data typeA whole number, not letters
RangeA number is within set limitsA mark from 0 to 100
LengthIt has the right number of charactersA password of at least 8
LookupIt is one of a list of allowed valuesA size that must be S, M or L
FormatIt follows a set patternA date like DD/MM/YYYY
Input sanitisation removes unwanted characters, such as quotation marks and semicolons, from an input so it cannot be used to attack the program.
Verification checks the data was entered correctly, for example by typing an email address twice (double entry). Validation checks data is sensible. Verification checks it is what you meant.
In the exam: name the check, then say how it is used for the rule in the question.

ActivitySort it: which validation check?

ActivityFill the gaps: which check?

Step 3

Authentication

Confirming who the user is.

Logging in

Log in
Hint: username sam, password Tiger22
Authentication: the program checks the username exists and the password matches it. Try the right login, then a wrong one.

Key facts

Authentication = confirming the identity of a user.
Only allowed (authorised) users can get access.
Way to authenticateHow it confirms who you are
Username and passwordThe password must match the username
Biometrics (fingerprint, face scan)Uses a feature of the user’s body to confirm who they are
Two-factor authentication (2FA)Needs two different proofs, e.g. a password AND a code sent to the user’s phone
CAPTCHA (“I am not a robot”)Checks the user is a real person, not a bot

Don’t mix up: authentication checks WHO the user is. Validation checks the DATA is sensible.

ActivitySort it: authentication or validation?

ActivityPut the login steps in order

Step 4

Maintainability

Code that other programmers can understand and update.

Hard or easy to maintain?

Key facts

Maintainable code is easy for other programmers to read, understand and update.
There are four ways to do it.
FeatureHow it helps
Sub programs (functions and procedures)Split the program into smaller parts that can be reused, tested and fixed
Naming conventionsMeaningful names show what a variable stores
IndentationShows which lines belong together (loops, if statements)
CommentingExplains what the code does, so others can follow it

Also credited: a constant (e.g. VAT = 0.2) means a value only has to be changed in one place.

In the exam: use an example from the code in the question.

ActivitySort it: which maintainability feature?

ActivityImprove the code

ActivityFill the gaps

Step 5

Exam questions

Type your answer, then mark it against the mark scheme.

Step 6

Challenges

Test yourself! Answer 10 questions correctly to finish this step.

Complete

0

Points

0
To finish the step0 / 10
Challenge

Loading…

BuryComputing – Created by Mr R. Brown © 2026
BuryComputing

Defensive design

Planning programs that cope with misuse. OCR J277 2.3.1.

1. Work throughSix short steps, one small part at a time.
2. Check itActivities unlock key-term stickers.
3. End of lessonPress 📝 Get my feedback and paste it into OneNote.


📝 Your feedback

Copy this and paste it into OneNote.