# Abstraction

URL: https://softwaredictionary.org/terms/abstraction
Category: Programming Fundamentals
Last updated: 2026-10-03
In Turkish: Soyutlama
Pronunciation: ab-STRAK-shun

In short: Abstraction is hiding the complicated details of how something works behind a simpler interface, so code can use it by knowing only what it does.

## What is abstraction in programming?

Every layer of software is an abstraction over the one below. A function `sendEmail(to, subject)` hides SMTP connections and retries; a file system hides disk sectors; a programming language hides machine instructions. Callers work with the simple idea and rely on it behaving as promised, which lets people build large systems without holding every detail in their heads.

In object-oriented programming, abstraction is one of the four classic principles, alongside encapsulation, inheritance and polymorphism. Interfaces and abstract classes describe what a type can do without saying how: a `PaymentProvider` interface with a `charge()` method can be implemented by a card processor or a test fake, and the rest of the code doesn't need to know which one it got.

Good abstractions have clear names, small surfaces and few surprises. Bad ones either hide too little, forcing callers to know the details anyway, or hide too much, making it impossible to handle an important case. Removing duplication too early often creates the second kind, a wrong abstraction that is harder to change than the repeated code was.

A common misconception is that abstraction and encapsulation are the same. Abstraction is about the design, exposing only the essential idea; encapsulation is the mechanism of keeping internal state private. Also, every abstraction leaks sometimes: a network call hidden behind a simple function can still be slow or fail, as Joel Spolsky's 2002 law of leaky abstractions describes.

## Key takeaways

- Abstraction hides how something works behind what it does.
- Software is built from layers of abstraction, from hardware up.
- Interfaces and abstract classes are the main OOP tools for it.
- Good abstractions are small and predictable; wrong ones are costly.
- Abstractions leak: hidden details such as slowness can still show through.

## Example: An interface hides which payment provider is used (TypeScript)

```typescript
interface PaymentProvider {
  charge(amountCents: number, customerId: string): Promise<string>;
}

class CardProcessor implements PaymentProvider {
  async charge(amountCents: number, customerId: string) {
    // HTTP calls, retries and error codes live here, hidden from callers
    return "txn_123";
  }
}

// Checkout depends on the abstraction, not on the details
async function checkout(provider: PaymentProvider, total: number, customer: string) {
  const transactionId = await provider.charge(total, customer);
  return { ok: true, transactionId };
}
```

## Frequently asked questions

**What is the difference between abstraction and encapsulation?**

Abstraction decides what to show: a simple interface that captures the essential idea. Encapsulation is how the rest is kept hidden: private fields and methods that outside code can't touch.

**What is an abstract class?**

A class that can't be instantiated directly and may leave some methods unimplemented. Subclasses fill in the details. Unlike an interface, it can also contain shared code and fields.

**What is a leaky abstraction?**

An abstraction whose hidden details still affect the people using it. For example, an ORM hides SQL, but slow queries still force developers to understand the SQL it generates.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
