Defensive Design
Aligned to the OCR J277 specification
- Level
- Intermediate
- Reading time
- 7 min
- Published
- 11 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- Defensive design means writing programs that anticipate problems - accepting only valid input, verifying user identity, and keeping code maintainable.
- Input validation checks that data meets defined rules (range, type, length, presence, format, or lookup) before the program processes it, using a WHILE loop so invalid input is re-requested.
- Authentication confirms a user's identity before granting access; limiting login attempts to three is a security improvement over a single attempt.
- A common mistake: validation only checks that data is in an acceptable form, not that it is correct - age 150 can pass a 0-120 range check.
- Maintainability techniques include using sub-programs, descriptive naming, consistent indentation, and purposeful comments that explain why, not what.
Something not quite clicking?
Ask Aica to explain any part of this differently. Free, takes 30 seconds.
Key terms
- Defensive design
- An approach to writing programs that anticipates problems such as invalid input or unauthorised access, and handles them without crashing.
- Input validation
- Checking that data entered by a user meets defined rules before the program processes it. Invalid data is rejected and the user is re-prompted.
- Range check
- A validation check that ensures a value falls within acceptable limits, for example that an age is between 0 and 120.
- Type check
- A validation check that confirms data is of the correct type, for example that a score is an integer rather than a string.
- Length check
- A validation check that ensures input meets length requirements, for example that a password is between 8 and 20 characters.
- Presence check
- A validation check that confirms a field is not empty.
- Format check
- A validation check that confirms input matches a required pattern, for example that a postcode is in a valid format.
- Lookup check
- A validation check that confirms a value appears in an approved list, for example that an answer is A, B, C, or D.
- Authentication
- The process of confirming a user's identity before granting access to a system, typically using a username and password.
- Maintainability
- The quality of code that makes it easy for other programmers to understand, modify, and extend without introducing new bugs.
Frequently asked questions
Validation checks that input data meets format or range rules, for example that a score is between 0 and 100. Authentication checks the identity of a user by verifying credentials such as a username and password.
An IF statement checks the condition only once and rejects bad input without asking again. A WHILE loop repeats the input request until valid data is entered, which is the required behaviour for input validation.
The four techniques are: use of sub-programs to break code into named, single-purpose routines; descriptive naming conventions; consistent indentation to show block structure; and comments that explain why something is done rather than restating what the code does.
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Subroutines and Scope
Testing Programs
Related lessons
7 min
8 min
6 min
9 min