Introduction
Once a problem has been decomposed into smaller tasks, it is useful to try and identify common themes or patterns that might exist within our program or with other programs.
This helps the programmer to save time reinventing the wheel when a solution to a given problem may already exist.
In this lesson, we’ll learn about:
- What is a pattern?
- Identifying and describing trends and similarities within and between problems and processes
- Identifying and describing common features between a given problem and existing solutions
- Making predictions and assumptions based on identified patterns
 
                                                                                                    What is a Pattern?
A pattern is something that repeatedly occurs in many different programming problems.
Patterns exist everywhere. If you were to look at how your day is organised from school to college, you would see that it follows a pattern:
- Your day will start at a set time.
- It will be broken up into a number of lessons of a set time.
- You will have a lesson with a teacher.
- The teacher will take a register.
- You may or may not be set homework for a particular lesson.
This pattern holds true for each day of the week for most students in most schools and colleges.
 
                                                                                                    What is a Pattern?
This pattern can then be applied to any systems that track and monitor student data, including attendance, punctuality and recording homework marks.
This is because most schools and colleges follow the same pattern.
This means that one program solution can be used by many different educational organisations.
Recognising patterns – things that are common within or between problems or programs – is one of the key areas of computational thinking.
 
                                                                                                    Identifying Trends Between Problems
Once you identify patterns in your problem, you might find that you need to use the same pattern again and again within your problem.
For example, you might want to display a graph of student attendance. This may be needed by:
- Staff to be able to monitor overall student attendance.
- Parents to be able to monitor the attendance of their son or daughter.
This would have the same graph pattern being used twice within the program.
 
                                                                                                    Identifying Common Solutions To a Problem
Once you identify a common pattern, there is more than likely an existing solution to the problem.
For example, you might want to search for a student in a school’s Information Management System.
To do this, you would need to use a searching algorithm, like a binary or linear search.
Note: We will look at searching algorithms later on in the course.
 
                                                                                                    Identifying Common Solutions To a Problem
Also, looking at the graph drawing problem from the previous section, Python contains a module called Matplotlib.
Matplotlib is a low-level graph plotting library that serves as a simple way of drawing and visualising graphical data. It is open-source and can be used freely by anyone.
This could be used as a solution for drawing graphs of student attendance.
Note: Matplotlib is one of the modules you are required to know for Paper 1 and the Employer Set Project.
 
                                                                                                    Making Predictions Using Patterns
Once you have identified a pattern, you can speculate whether it can be reused in your existing program or used in another program.
You can also examine the pattern to identify any software or hardware components you might need.
For example, you identify that you need a login system for a program as:
- A user must input a username and password.
- The inputs are compared to the data stored in a database.
- If the inputs match, the user is logged into the system.
Based on this, you can predict you will need a user interface, a database to store usernames & passwords, some means of connecting the interface to the database, and some form of loop if the user gets their username or password wrong.
 
                                                                                                    Lesson Summary
Patterns are things that are the same within a problem and between problems.
Identifying patterns means that there is probably an existing solution already out there.
Patterns can be repeated within a problem.
Patterns can be repeated between problems.
If a pattern is identified, then it is possible to predict what hardware and software components may be needed to solve that problem.
