Course 7.1Lesson 2 of 3
Every computer system is made of sub-systems, and each sub-system is made of smaller ones. You decompose a problem into its inputs, processes, outputs and storage, use abstraction to keep only what matters, and draw a structure diagram that shows the parts of a system.
Try the code and the simulations beside the lesson.
How do you cook a meal for ten people? You do not think of it as one job. You plan the starter, the main dish and the pudding. The main dish splits again: buy the food, prepare it, cook it. Each small job is easy to do and easy to check.
A computer system is the same. Every computer system is made up of sub-systems, which are made up of further sub-systems. A sub-system is one part of a system that does one part of the job.
Decomposition means breaking a problem into smaller parts. The syllabus asks you to break a problem into four kinds of component part.
Here is a fitness band that counts steps.
Why decompose? Each small part is easier to understand, design, code and test. Different programmers can work on different parts at the same time. A part that already exists, such as a routine that sorts a list, can be used again.
A map of a bus route shows the stops and the order of the stops. It does not show every house and tree. The map keeps what a passenger needs and leaves out the rest. That is abstraction: removing the details that do not matter to the problem, so that you can work with the ones that do.
In a quiz program, each question needs its text, its options and its right answer. The size of the font on a printed quiz does not matter to the program, so it is left out. Abstraction makes a problem smaller and clearer before it is decomposed.
A structure diagram shows how a system is decomposed. The whole system is the box at the top. Each level below breaks the box above it into its parts. The lowest boxes are small tasks that can each be written as one part of the program.
The diagram above decomposes a school library system into three sub-systems: members, loans and fines. Each of those splits again. For example, the loans sub-system has two tasks: lend a book and return a book. Read the diagram from the top down. A box always belongs to the box it is joined to above it.
In a program, each box of a structure diagram can become a subroutine: a named block of code that does one task. In Python a subroutine is written with def. You met functions in the Python Foundations book (the chapter "Functions: Name a Recipe"). The program below splits the ticket program into three sub-tasks.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place in the course.