1.1.1 Decomposition & abstraction
Decomposition
Decomposition is the process of breaking a complex problem down into a set of smaller, more manageable sub-problems. Each sub-problem is easier to understand, design and solve independently. When all the sub-problems are solved, their solutions are combined to solve the original problem.
Decomposition is used throughout software development — from the initial design stage right through to testing. A large program is typically decomposed into modules or subprograms, each responsible for one specific task.
Example: Building a quiz game
The overall problem: create a quiz game can be decomposed into:
- Display a question and possible answers
- Accept and validate the player's answer
- Check whether the answer is correct
- Update and display the score
- Decide whether the game is over
Each of these sub-problems can be decomposed further if needed — for example, "accept and validate the player's answer" might be split into "read the input" and "check it is a valid option".
Abstraction
Abstraction is the process of removing unnecessary detail from a model of a real-world situation, keeping only what is relevant to solving the problem at hand. It allows a programmer to focus on the key features of a problem without being overwhelmed by complexity.
Abstraction appears at many levels in computer science:
- Problem abstraction: when modelling a bus route in a journey planner, you keep stop names and timetables but ignore the colour of the buses or the driver's name.
- Data abstraction: a variable called
scorehides the detail of exactly how numbers are stored in memory. - Procedural abstraction: calling
calculate_total()uses the result without needing to know how it is calculated internally.
Example: Modelling a library system
Relevant details to keep: book title, author, ISBN, whether it is on loan.
Details to remove: the font on the book cover, the weight of each book, the shelf colour.
Why Both Matter
Decomposition and abstraction work together. Decomposition identifies what needs to be solved; abstraction clarifies what information is needed to solve each part. Together they allow programmers to model complex real-world systems in a way that is both understandable and implementable.
- Problems become smaller and less intimidating.
- Sub-problems can be developed and tested independently.
- Solutions to sub-problems can be reused in other projects.
- Teams can work on different sub-problems simultaneously.
Key Takeaways
- Decomposition = breaking a complex problem into smaller sub-problems.
- Abstraction = removing unnecessary detail, keeping only what is relevant.
- Both are used to model real-world situations computationally.
- Together they make problems easier to analyse, understand and solve.