AQA 7517, section 4.13.1.2
Once you know what is needed, plan the solution in detail before you build it. Design turns the requirements found in analysis into a plan that programmers can follow. A good design makes the program easier to write, test and maintain, and avoids costly mistakes.
Design includes planning:
- the data structures for the data model;
- the algorithms;
- an appropriate modular structure;
- the human user interface.
1. Data structures for the data model
Decide how the data will be stored in the program or database.
- Which data structures: arrays or lists, records, dictionaries, stacks, queues, trees or database tables?
- What data type is each item (integer, string, date), and what validation does it need?
- How will it be stored permanently (a text file, a binary file or a relational database)?
For the library system, the entity BOOK (ISBN, Title, Author) might become a record (or class) stored in a dictionary keyed by ISBN, so that a book can be found quickly.
2. Algorithms
Plan the steps that solve each part of the problem, using pseudo-code or a flowchart, before writing any code. This lets you check the logic and trace it with test data.
FUNCTION is_overdue(date_due, today)
IF today > date_due THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION
Choose algorithms that are efficient where it matters (for example, a binary search of sorted data, not a linear one).
3. A modular structure with documented interfaces
A large problem is decomposed (4.4.1.9) into smaller modules (subroutines or classes), each with one clear job. Designing an appropriate modular structure means deciding:
- what the modules are and how they fit together (a hierarchy chart is often used, see 4.1.2.2);
- the interface of each: its name, parameters, what it returns, and what it does;
- how they will be documented, so that each programmer knows how to use a module without seeing inside it.
A documented interface for one module:
| Item | Description |
|---|---|
| Name | lend_book |
| Purpose | Records that a student has borrowed a book |
| Parameters | student_id (integer), isbn (string) |
| Returns | True if the loan was recorded, False if the book is already on loan |
| Uses | find_book, find_student |
If the interfaces are clearly specified, several people can work on different modules at the same time, and each module can be written and tested separately. This is the benefit of structuring programs into modular parts (see also 4.1.2.2).
4. The human user interface
The user interface is how people use the program. It should be designed for the intended users, and early.
Points to consider:
- Layout: a clear, consistent arrangement of menus, buttons and fields, with the most important items easy to find.
- Input: appropriate controls (drop-down lists, tick boxes, date pickers) and validation to stop invalid data.
- Output: results presented clearly, with readable fonts, colours and enough contrast.
- Feedback and error messages: tell the user what is happening, and give helpful messages if something goes wrong, such as "Please enter a date in the form DD/MM/YYYY".
- Ease of use: simple, minimal steps to carry out common tasks, and suitable for the users' skill level.
- Accessibility: usable by people with different needs, such as a larger text option or screen reader support.
A designer often draws sketches or wireframes of each screen, and shows them to users before building them.
Design as an iterative process
Design rarely gets everything right first time, so it is usually done in cycles, using a prototyping or agile approach. A first design is drawn up, a prototype is built and shown to users, and their feedback is used to improve the design, perhaps several times. It's better to find a weakness in a sketch than in finished code.
Test planning
At the design stage, it's also good practice to plan how the system will be tested, using the requirements: what test data will be used, and what result is expected. This is covered in 4.13.1.4.
Worked example
Task: design the main parts of a simple quiz program that asks 5 questions and shows the score.
- Data structures: a list of records, each holding a question, the correct answer and a list of options. The score is an integer.
- Algorithms: a loop that, for each question, displays it, reads an answer, checks it and adds 1 to the score if it is correct.
- Modules and interfaces:
| Module | Parameters | Returns |
|---|---|---|
load_questions() |
none | list of question records |
ask(question) |
one record | the user's answer |
check(question, answer) |
a record and a string | True or False |
show_result(score, total) |
two integers | nothing (displays a message) |
- User interface: one question per screen, with large clickable options, a progress indicator ("Question 3 of 5"), and a final screen showing the score. Mock-ups are shown to a few students for comments before coding starts.
Check yourself
Name four things that should be planned in the design stage
The data structures for the data model, the algorithms, an appropriate modular structure, and the human user interface.
Why should the interface of each module be clearly documented?
So that programmers know how to use each module without seeing its inside, which lets different people write and test modules independently and use them correctly.
Give three considerations when designing a user interface
Any three of: a clear, consistent layout; appropriate input controls and validation; readable output; helpful feedback and error messages; ease of use for the intended users; accessibility.
Why can design be an iterative process?
A prototype can be built and shown to users, and their feedback used to improve the design, perhaps several times, so problems are found early.