Abstraction
Абстракция
In programming, it means working with the parts of an operation or object that matter to your task without needing to know how the rest is implemented.
What abstraction means
When you call sort(items), you ask for an ordering rather than spelling out every comparison and move. You still need to know whether the function changes items or returns a new collection, because that choice affects the rest of your code. Abstraction is about choosing which details the caller needs, not hiding as much as possible.
The contract is what callers rely on
An abstraction gives callers a contract: what they can ask for, what they get back, and what behavior they can depend on. A signature describes the shape of the inputs and outputs, but it rarely tells the whole story. A sorting function might also promise that items with equal keys keep their original order. If it does, switching algorithms is an internal change only if the new algorithm preserves that guarantee.
Example: a delivery date
from datetime import date
def show_delivery_date(estimate, postal_code: str) -> str:
day: date = estimate(postal_code)
return f"Estimated delivery: {day:%B %d}"
show_delivery_date formats a date; it leaves the calculation to estimate. In production, that callable could check a carrier's schedule. In a test, it could return a fixed date so the test checks formatting without depending on a live service. No abstract class is needed: the callable is the boundary. If a postal code might be unsupported, the caller and the estimator still need to agree on what happens. The ability to pass in a different function doesn't make every function with the same signature a valid replacement.
Where it helps and where it goes wrong
Abstraction shows up in functions, data structures, and APIs. A queue lets the caller add an item and retrieve the oldest one without tracking storage positions. That's the abstraction. Preventing callers from modifying the underlying buffer directly is encapsulation: it helps protect the queue's behavior. The two often work together, but they solve different problems.
A new layer isn't automatically useful. A wrapper that repeats the names, parameters, and errors of the underlying library may add another file to navigate without giving callers anything simpler to rely on. Conversely, a wrapper that exposes too little can force callers to guess. For example, if they need to distinguish a temporary service outage from an unsupported postal code, returning the same empty value for both hides a detail they actually need.
How it comes up in interviews
You may be asked to identify an abstraction in a code sample or decide whether to extract one during a refactor. Explain what the caller is trying to do, what behavior must stay stable, and what would be free to change behind the boundary. If two pieces of code look similar but follow different rules, say which differences matter before proposing a shared interface.