Abstraction Examples in CS Thinking

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Abstraction.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.

Concept Recap

Focusing only on the essential information needed to solve a problem while ignoring irrelevant details. Abstraction reduces complexity by creating simplified models that capture what matters and hide what does not, enabling reasoning at higher levels.

Zooming out to see the big picture, hiding complexity you don't need right now.

Read the full concept explanation โ†’

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

Core idea: Good abstraction reveals what matters and hides what doesn't.

Common stuck point: Too much abstraction loses important information; too little is overwhelming.

Sense of Study hint: When applying abstraction, first identify which details are essential to solving your current problem and which are irrelevant. Remove or hide the irrelevant details, creating a simplified model. Test whether your abstraction still captures enough information to produce correct results.

Worked Examples

Example 1

medium
A map of the London Underground is an example of abstraction. Explain what details are kept and what is removed.

Answer

The Tube map keeps connectivity and line information but removes geographic accuracy. This makes it easier to plan journeys.

First step

1
Step 1: Details kept: station names, line colours, connections between stations, order of stations.

See the full worked solution + why-it-works coaching

SetupKey insightWhy it worksCommon pitfallConnection

Unlock answer keys One Family plan โ€” every worked solution, all subjects

Example 2

medium
A function `calculateArea(length, width)` returns `length * width`. Explain how this is an example of abstraction.

Example 3

medium
A `User` object exposes `getEmail()` but stores email in a private field. Why is direct field access discouraged?

Example 4

medium
A REST API exposes `/users/{id}` returning JSON. Compare two abstractions hidden behind the endpoint: storage and serialization.

Example 5

medium
Joel Spolsky's 'Law of Leaky Abstractions': give one concrete example where a network library's abstract `send()` leaks the underlying network.

Example 6

hard
Compare procedural abstraction (function) and data abstraction (ADT). Give one example each and what is hidden.

Example 7

hard
A `Database` interface has `commit()` and `rollback()`. What concurrency-control complexity does this abstract?

Example 8

hard
An HTTP client library exposes `get(url)`. List three layers of abstraction stacked beneath this single call.

Example 9

challenge
A `Monad` (e.g., `Maybe`/`Option`) abstracts what aspect of computation?

Example 10

challenge
Lambda calculus has only variables, function abstraction, and application. Argue why this minimal system is Turing-complete despite hiding so much.

Example 11

medium
A weather app needs to alert users about thunderstorms. List one ESSENTIAL detail to keep in the model and one IRRELEVANT detail to abstract away.

Example 12

medium
Two functions need to draw shapes: drawSquare(side), drawCircle(r). Designing a Shape abstraction, what one method should each implement?

Example 13

hard
You are designing a `RideShare` abstraction for a class project. Identify two essential details to keep and two to abstract away when modeling a 'Ride'.

Example 14

hard
A 'Payment' abstraction exposes `charge(amount)`. Card and wallet implementations both implement it. The team adds 'split payment across multiple methods.' Why might this break the abstraction?

Example 15

challenge
Levels of abstraction in CS: transistor -> gate -> CPU -> assembly -> high-level language -> framework. A bug at the framework layer is traced to integer overflow in the CPU. Which abstraction failure does this exemplify?

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

easy
When using a TV remote, you press 'Volume Up' without knowing the electronics inside. How does this illustrate abstraction?

Example 2

easy
A weather app shows temperature, rain chance, and wind speed, but hides sensor voltages and calibration values. What information is abstracted away, and why is that useful?

Example 3

easy
A subway map shows lines and stops but not exact distances or streets. Hiding irrelevant detail to show only what matters is called what?

Example 4

easy
To use a 'sort' function you only need its name and inputs, not its internal code. What concept lets you ignore the internals?

Example 5

easy
For 'find the fastest route', which detail is ESSENTIAL: (a) road travel times, (b) the color of the cars?

Example 6

easy
True or false: a good abstraction is precise about exactly what it exposes and what it hides.

Example 7

easy
A 'Car' class exposes drive() and brake() but hides the engine wiring. The hidden internals are an example of what abstraction principle?

Example 8

easy
A weather app reports just 'rain expected' instead of full atmospheric data. This simplified report is a model created by what?

Example 9

easy
Levels of abstraction: high-level language -> assembly -> machine code. Which is the HIGHEST level (most detail hidden)?

Example 10

easy
A function named computeTax(income) hides the formula inside. To use it you treat it as a what?

Example 11

medium
Two map models exist: Model A keeps every pothole and tree; Model B keeps roads and intersections. For routing, which is better-abstracted and why?

Example 12

medium
A program models a student as just {id, gpa}, dropping name and address. If a transcript feature later needs the name, what abstraction error occurred?

Example 13

medium
An 'Animal' type defines makeSound(). Dog and Cat implement it differently. The shared makeSound() interface is an abstraction over what?

Example 14

medium
A model of a coin flip ignores air, spin, and force, keeping only 'heads or tails with p=0.5'. Why is dropping the physics a GOOD abstraction here?

Example 15

medium
An API exposes getBalance() but a developer reaches into the internal _ledger array directly. Which abstraction principle did they violate?

Example 16

medium
Stack abstraction exposes push and pop only. After push(1), push(2), push(3), pop(), what value is now on top?

Example 17

medium
A temperature sensor returns floats like 21.347891. A display abstracts this to '21 C'. What two things does this abstraction do?

Example 18

medium
A 'User' model for a login system keeps {username, passwordHash}. Should it also store the user's favorite color for login? Answer and justify.

Example 19

medium
A queue ADT exposes enqueue and dequeue (FIFO). After enqueue(1), enqueue(2), enqueue(3), dequeue(), what value is returned?

Example 20

challenge
Designing a 'Shape' abstraction with area(), you must decide what each shape stores. Why is exposing only area() (not the formula) the right boundary?

Example 21

challenge
Two abstraction layers: a database driver hides SQL details; an app uses save(user). If the database changes from MySQL to Postgres but save(user) is unchanged, what property did the abstraction provide?

Example 22

challenge
A simulation abstracts a city as a grid of cells, each 'empty' or 'full'. A planner says this ignores building heights. When is dropping height a correct abstraction, and when is it an error?

Example 23

easy
A function `length(str)` returns the number of characters but hides how it counts them. What CS principle does this illustrate?

Example 24

easy
A `Car` class has methods `start()` and `stop()` but the engine internals are private. What OOP principle is shown?

Example 25

easy
A file's contents are read with `open(path)` regardless of whether the file is on disk, in RAM, or on a network drive. What kind of abstraction enables this?

Example 26

medium
A `Sortable` interface declares `compareTo(other)`. Which design pattern does this enable across `Integer`, `String`, `Date`?

Example 27

medium
TCP gives applications a reliable, in-order byte stream over an unreliable packet network. Name two details the TCP abstraction hides.

Example 28

medium
An `Iterator` exposes `hasNext()` and `next()`. What does this abstract over, exactly?

Example 29

medium
A `Logger` class lets callers do `log.info("hi")`. List one good abstraction (what users see) and one leak (what they have to know about anyway).

Example 30

hard
An ORM maps SQL rows to objects. State one abstraction win and one anti-pattern this layer commonly creates.

Example 31

hard
Virtual memory makes each process believe it has its own address space. What two concrete benefits does this abstraction provide?

Example 32

hard
When is choosing an abstraction TOO early in a project a problem?

Example 33

hard
Why is `O(1)` for hash-table lookup an idealized abstraction rather than literally true?

Example 34

medium
A `RandomNumber` interface lets a test inject a deterministic stub. What design technique is this, and what abstraction is exposed?

Example 35

challenge
A microservices architecture replaces in-process function calls with network requests. Name one abstraction strengthened and one weakened by this move.

Example 36

easy
A car dashboard shows the speed but hides the engine RPM and fuel-injection math. Hiding internal details behind a simple display is an example of what?

Example 37

easy
When designing a 'Book' model for a library catalogue, which detail is ESSENTIAL: (a) title and author, (b) the color of the librarian's shoes?

Example 38

easy
Using a hand calculator, you press '7 + 3 =' to get 10 without knowing the binary circuitry. The simple keypad interface is an example of what?

Example 39

easy
True or False: a vague description is the same as a good abstraction.

Example 40

easy
A list ADT exposes `add`, `remove`, and `length`. To use it, do you need to know how the list stores items in memory?

Example 41

easy
A school's 'Student' model stores {id, grade, attendance}. For computing class average grade, which fields are essential?

Example 42

medium
A simulation models a planet as a point with mass and position, ignoring its shape and rotation. For computing the planet's orbit around a star, is this a GOOD abstraction?

Example 43

medium
A model represents a person as just `{age}`. A new feature needs to send email reminders. What is the abstraction error?

Example 44

medium
A program models every car with 200 attributes โ€” make, color, VIN, every bolt, every paint pigment. For a simple parking app, what kind of abstraction error is this?

Example 45

medium
A `print` function lets you call `print(x)` regardless of whether xx is an integer, string, or list. The function chooses the right formatter internally. What abstraction concept is this?

Example 46

medium
A `Tree` class exposes `insert`, `find`, and `delete`. After `insert(5)`, `insert(3)`, `insert(7)`, `find(3)`, the result is the node containing 3. Does the user need to know the tree is balanced as a red-black tree?

Example 47

medium
A queue ADT exposes enqueue and dequeue. After enqueue(7), enqueue(8), enqueue(9), dequeue(), dequeue(), what value is returned by the second dequeue?

Example 48

medium
A stack ADT exposes push and pop. After push(1), push(2), push(3), pop(), pop(), what value is returned by the second pop?

Example 49

medium
A file system exposes open(), read(), write(), close(). Application code uses these without knowing about disk sectors. What property does this give application code if the OS later switches to an SSD?

Example 50

hard
A 'leaky abstraction' is one whose hidden internals affect the user in surprising ways. Give a brief example.

Example 51

hard
An ORM abstracts SQL behind objects like `User.find(id)`. A team uses it to write `for u in Users: u.posts` which secretly emits 10000 queries. What abstraction failure occurred?

Example 52

hard
A coding interview asks for a function `path_exists(graph, start, end)`. The candidate writes BFS. From the caller's perspective, the function is an abstraction over what implementation choice?

Example 53

hard
A 'distance' abstraction in a maps app returns kilometers between two points. To support walking directions, the team needs elevation. Which is the cleaner change?

Example 54

challenge
A self-driving car system exposes `goTo(destination)`. Internally it must handle sensors, maps, prediction, and control. Suppose the abstraction silently fails in bad weather. What design principle would have helped surface this risk to callers?