2.1.1 Thinking Abstractly
2.1.1(a) The Nature of Abstraction
Types of Abstraction
| Type of abstraction | What it does | Typical example |
|---|---|---|
| Representational abstraction | Removes irrelevant detail from a model | A map that shows roads but not every building interior |
| Abstraction by generalisation | Finds common patterns to use one shared solution | Treating dogs/cats/birds as Animal objects |
| Data abstraction | Hides storage/implementation details behind an interface | Using a stack without knowing its internal structure |
| Procedural abstraction | Breaks problems into reusable procedures/functions | Calling calculateTotal() without knowing internals |
| Level | Typical focus | Example in an email app |
|---|---|---|
| High level (user interface) | What the user sees and does | Click "Send" button |
| Middle level (program code) | How behaviour is implemented | sendEmail(to, subject, body) |
| Low level (hardware/machine) | How instructions execute physically | CPU executes machine instructions |
2.1.1(b) The Need for Abstraction
| Why abstraction matters | Benefit |
|---|---|
| Simplification | Reduces complexity so problems are easier to understand and solve |
| Efficiency in design | Speeds development by focusing only on relevant system parts |
| Layered architecture | Lets each layer (e.g. TCP/IP) be designed/tested independently |
| Accessibility | Enables non-specialists to program without machine-level detail |
| Layer | Example protocol/tech | Responsibility |
|---|---|---|
| Application | HTTP, FTP, SMTP | User-facing network services (e.g. sending email) |
| Transport | TCP | Reliable end-to-end delivery |
| Network | IP | Addressing and routing across networks |
| Data Link | Ethernet, Wi-Fi frames | Local network transmission |
| Physical | Cables, radio signals | Raw signal transmission |
2.1.1(c) The Difference Between Abstraction and Reality
Representing Reality in Code
| Real-world car detail | Included in simple Car abstraction? |
|---|---|
| Thousands of mechanical parts | No |
| Wear and tear history | No |
| Fuel and engine thermodynamics | No |
| Current speed/state | Yes |
| Actions like start/brake | Yes |
class Car:
private colour
private model
private speed
private isRunning
public procedure start()
public procedure accelerate(amount)
public procedure brake()
public function getSpeed()
end class
The abstraction keeps the essentials for the task and omits unnecessary physical complexity.
| Real-world version | Abstract program model |
|---|---|
| Names on paper list | studentNames array/list |
| Re-order manually | studentNames.sort() |
| Add a new name manually | studentNames.add("Eve") |
| Count names manually | length(studentNames) |
studentNames = ["Alice", "Bob", "Charlie", "Diana"]
studentNames.sort()
studentNames.add("Eve")
count = length(studentNames)
The array abstraction hides memory allocation and low-level storage mechanics.
2.1.1(d) Devise an Abstract Model for a Variety of Situations
| Design consideration | Questions to ask |
|---|---|
| Problem definition | What exactly needs solving? Which features are essential? |
| Model usage | How will it be used in practice? Is it practical and accessible? |
| Target audience | Who will use it and what is their expertise level? |
| Relevance vs simplicity | Which details are essential, and which can be removed? |
Real-world complexities we ignore:
• Physical layout of the library
• Colour of the carpet
• Temperature of the building
• Staff break schedules
Abstraction we keep:
record Book:
string ISBN
string title
string author
boolean isAvailable
end record
record User:
string userID
string name
list borrowedBooks
end record
record Loan:
string bookISBN
string userID
date borrowedDate
date dueDate
end record
```key-point
| Key operation | Purpose |
|---|---|
| borrowBook(userID, ISBN) | Create a loan and mark a book unavailable |
| returnBook(userID, ISBN) | Close loan and mark book available |
| searchBooks(query) | Find books by title/author/ISBN |
| checkOverdueLoans() | Identify late returns |
This abstraction captures what matters for the system while ignoring irrelevant physical details.
Exam Tips for Abstraction:
• Be able to explain why abstraction is necessary (simplification, efficiency, layered architecture, accessibility)
• Identify similarities and differences between real-world and abstract representations
• Explain the four types: representational, generalisation, data, and procedural abstraction
• Devise appropriate abstract models for given scenarios
• Understand how abstraction relates to OOP objects, data structures, and layered systems
```