H446/02 · Algorithms & ProgrammingSection 2.1

2.1.1 Thinking abstractly

Nature of abstraction, representational abstraction, generalisation, data and procedural abstraction, devising abstract models

📚2.1.1 Thinking Abstractly

2.1.1(a) The Nature of Abstraction

Definition
Abstraction is a fundamental concept in computer science that involves simplifying a problem by removing unnecessary details, allowing us to focus only on the essential aspects. This process helps in creating a model or representation that is easier to work with and understand.

Types of Abstraction

Key Point
Type of abstractionWhat it doesTypical example
Representational abstractionRemoves irrelevant detail from a modelA map that shows roads but not every building interior
Abstraction by generalisationFinds common patterns to use one shared solutionTreating dogs/cats/birds as Animal objects
Data abstractionHides storage/implementation details behind an interfaceUsing a stack without knowing its internal structure
Procedural abstractionBreaks problems into reusable procedures/functionsCalling calculateTotal() without knowing internals

Worked Example
Levels of Abstraction Example

LevelTypical focusExample in an email app
High level (user interface)What the user sees and doesClick "Send" button
Middle level (program code)How behaviour is implementedsendEmail(to, subject, body)
Low level (hardware/machine)How instructions execute physicallyCPU executes machine instructions
Each level serves a different purpose, from user interaction down to hardware execution.

2.1.1(b) The Need for Abstraction

Key Point
Why abstraction mattersBenefit
SimplificationReduces complexity so problems are easier to understand and solve
Efficiency in designSpeeds development by focusing only on relevant system parts
Layered architectureLets each layer (e.g. TCP/IP) be designed/tested independently
AccessibilityEnables non-specialists to program without machine-level detail

Worked Example
TCP/IP Layered Architecture (Abstraction Example)

LayerExample protocol/techResponsibility
ApplicationHTTP, FTP, SMTPUser-facing network services (e.g. sending email)
TransportTCPReliable end-to-end delivery
NetworkIPAddressing and routing across networks
Data LinkEthernet, Wi-Fi framesLocal network transmission
PhysicalCables, radio signalsRaw signal transmission
Each layer abstracts the complexity below it. A browser uses HTTP without handling electrical signalling details.

2.1.1(c) The Difference Between Abstraction and Reality

Definition
Abstraction creates a simplified model that represents reality without capturing all of its complexities. In computer science, real-world entities and processes are often represented using abstract models such as tables, databases, or objects in object-oriented programming (OOP).

Representing Reality in Code

Worked Example
Objects in OOP vs Real World

Real-world car detailIncluded in simple Car abstraction?
Thousands of mechanical partsNo
Wear and tear historyNo
Fuel and engine thermodynamicsNo
Current speed/stateYes
Actions like start/brakeYes

text
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.

Worked Example
Variables and Data Structures

Real-world versionAbstract program model
Names on paper liststudentNames array/list
Re-order manuallystudentNames.sort()
Add a new name manuallystudentNames.add("Eve")
Count names manuallylength(studentNames)

text
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

Key Point
Design considerationQuestions to ask
Problem definitionWhat exactly needs solving? Which features are essential?
Model usageHow will it be used in practice? Is it practical and accessible?
Target audienceWho will use it and what is their expertise level?
Relevance vs simplicityWhich details are essential, and which can be removed?

Worked Example
Library System Abstract Model

Real-world complexities we ignore:
• Physical layout of the library
• Colour of the carpet
• Temperature of the building
• Staff break schedules

Abstraction we keep:

text
record Book:
text
string ISBN
string title
string author
boolean isAvailable
text
end record

record User:
text
string userID
string name
list borrowedBooks
text
end record

record Loan:
text
string bookISBN
string userID
date borrowedDate
date dueDate
text
end record


```key-point
Key operationPurpose
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.

text
exam-tip
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
```