Abstraction
What is Abstraction?
Abstraction
The process of simplifying complex systems by focusing on essential details while ignoring irrelevant ones.
Abstraction allows us to manage complexity by creating generalised models that can be applied to various situations.
Abstraction is not about removing details entirely, it's about selecting the right level of detail for a specific context.
- Think of abstraction like a blueprint for a house.
- The blueprint shows the structure and layout without detailing every nail or piece of wiring.
- It provides a high-level view that guides construction while leaving out unnecessary specifics.
It allows you to:
- Manage complexity: By breaking down a problem into smaller, more manageable parts.
- Enhance clarity: By highlighting the most important aspects of a problem or solution.
- Facilitate reusability: By creating generalised solutions that can be applied to multiple situations.
Abstraction is a fundamental concept in computer science, enabling us to manage complexity by breaking down problems into manageable parts.
A recipe abstracts the cooking process by listing ingredients and steps without detailing every minor action, such as opening a cupboard or turning on a stove.
Abstraction can be defined on different levels:
High-Level Abstraction: Focuses on the overall structure or purpose.
A school system represented as faculties and departments.
and Low-Level Abstraction: Focuses on specific details or implementation.
A department represented by courses and instructors.
Abstraction in Computer Science
In programming, abstraction is used to create models of real-world entities through data structures, algorithms, and object-oriented design.
- Think of abstraction like a map.
- A city map highlights roads and landmarks, ignoring unnecessary details like individual trees or buildings.
- Similarly, abstraction in computer science focuses on the essential features of a problem, ignoring irrelevant details.
Applications include, but are not limited to:
- Functions and sub-procedures:
- Algorithms often use abstraction to define high-level steps without specifying low-level operations.
- Pseudocode:
- Pseudocode is a form of abstraction that describes an algorithm's logic without adhering to the syntax of a specific programming language.
- Data Structures:
- Abstract data types (ADTs) like stacks and queues provide a high-level interface for data manipulation, hiding the underlying implementation details.
- Object-Oriented Programming:
- Classes and objects abstract real-world entities by defining properties (attributes) and behaviours (methods) relevant to a specific context.
- Databases:
- Tables and queries abstract complex data relationships, allowing users to interact with data without understanding the underlying structure.
- Modelling and simulation:
- Simulations abstract real-world systems, focusing on key variables and interactions to predict behaviour.
- Web science:
- Distributed applications abstract network complexities, enabling seamless communication between systems.
A sorting algorithm might include a step to "swap elements" without detailing how the swap is performed.
- In a program that simulates a car, a Car class might include attributes like speed and fuelLevel, and methods like accelerate() and brake().
- This abstraction allows you to interact with the car's functionality without worrying about the underlying physics or engine mechanics.
- Different levels of abstraction are appropriate for different stages of development.
- High-level abstraction is helpful for planning and design, while low-level abstraction is necessary for implementation and optimisation.
Abstraction is a core principle of modular programming, where code is organised into independent, reusable modules.
The Process of Constructing Abstraction
- Identify the problem: Understand the situation or system you need to model.
- Determine the key components: Identify the essential elements and relationships.
- Ignore irrelevant details: Focus only on what is necessary for the current context.
- Create a simplified model: Represent the system using diagrams, pseudocode, or natural language.
When constructing an abstraction, always ask: "What details are essential for solving this problem?"
Real-World Entities and Abstraction
- Real-world entities are objects, concepts, or phenomena that exist in the physical or conceptual world.
- They have specific attributes and behaviours that define their nature and interactions.
| Real-world Entity | Attributes | Behaviours |
|---|---|---|
| Car | Color, speed, fuel level | Accelerate, brake, turn |
| Student | Name, age, grade | Study, attend classes, take exams |
| Weather system | Temperature, humidity, wind speed | Rain, snow, clear skies |
- Consider a program that simulates a traffic light system.
- Without abstraction, you might try to model every detail, from the electrical wiring to the colour of the lights.
- This approach would be overwhelming and inefficient.
- Instead, you can use abstraction to focus on the essential components:
- States: Red, yellow, and green.
- Transitions: The rules for switching between states.
- Timing: The duration of each state.
- By abstracting these core elements, you can create a flexible and reusable simulation that can be adapted to different traffic scenarios.
- A map is an abstraction of a territory.
- It highlights specific features like roads, rivers, and landmarks while omitting unnecessary details such as individual trees or buildings.
- Additionally, the territory itself is 3D, but the map is usually only in 2D.
- Without a specialised map, the level of the terrain is omitted.
- Can you identify the essential attributes and behaviours of a real-world entity you interact with daily?
- How would you create an abstraction of that entity for a specific purpose, such as a software application?
- How does abstraction help you manage complexity when designing algorithms or writing code?
- How does abstraction influence our understanding of complex systems?
- What are the epistemological implications of relying on abstract models to represent reality?