Menu

Abstraction

Abstraction is removing or hiding unnecessary detail from a problem so that attention can be focused on the essential components. When you abstract, you decide what really matters for the problem you are solving and leave everything else out.

Keeping only what matters

Abstraction is not about losing information by accident. It is a deliberate choice to keep the detail the problem needs and ignore the rest. Imagine you are writing a program for a school library that works out when a book is overdue. The date the book was borrowed and the number of days it can be kept are essential. The colour of the book's cover, who printed it and how heavy it is are not needed, so they are abstracted away.

Simplified models

Abstraction is how you build simplified models of real-world objects and systems that a program can work with. A model is a version of something real that keeps only the parts the program needs.

For example, a program that runs a school vending machine might model what the machine holds. The model stores the number of each slot, the snack in that slot, its price and how many are left. It ignores the colour of the machine's casing, who made it and what the buttons feel like, because none of that helps work out what should happen when a pupil types B4 and pays.

A model like this is much smaller and simpler than the real vending machine, which makes it quicker to work with and easier to program. The program can then answer the real question without being buried in details that make no difference to the answer.

Practise this