Defensive Design - Lakelands Computing

Title
Go to content
Defensive Design
Defensive Design helps make sure programs work the way they are meant to - without errors or bugs. To do this they try to:

Defensive Design helps make sure programs work the way they are meant to - without errors or bugs. To do this they try to:

Preventing program misuse
The easiest way for someone to misuse a program (either by accident or on purpose) is when they are entering data into the program (an SQL injection attack is a good use of deliberate misuse)

To prevent this type of thing programmers use input sanitisation . This is where any unwanted characters (such as special characters) are removed before the data is passed through to the program (not allowing the $ for example prevents a number of potentially damaging commands being used).

A second method is to use input validation. This checks if data as met certain criteria before it is passed on. Ths could be lenght checks (number of letters), if it is within an allowed number range, if the answer has been completed (presence check) etc. Click here for a more detailed look at validation.

User Authentication (making a user sign in and use a strong password) also protects from misuse by making sure only allowed users are using the program.

Well maintained code is easy for other programmers to understand. It is possible to change one part of the code without it affecting all the rest of the code. Easy to maintain code has:

  • Comments that explain what the key features of that section of code are
  • Indentation (code moved in) that is used to seperate different parts of the code (eg code that runs as part of the if statement is all indented the same (pushed in)
  • Sensible names for variables and functions that describe what they are for.
  • Local variables wherever possible (global variables only used when totally neccesary). Local variables only affect the subprogram they are part of not all the program.


All Text copyright Lakelands Academy & Mr T Purslow 2020.
All images copyright free / creative commons unless otherwise stated.
You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
All Text copyright Lakelands Academy & Mr T Purslow 2020.  All images copyright free / creative commons unless otherwise stated. You are welcome to use under a Creative Commons Attribution-nonCommercial-ShareAlike License.
Back to content