Abstract Classes

What Are the Three Types of Abstraction?

Abstraction in programming is often split into three types: data, control and procedural. Here is what each one means, with a short C++ example for each.

On this page
  1. The short answer
  2. What abstraction means
  3. Data abstraction
  4. Procedural abstraction
  5. Control abstraction
  6. Where this leaves you

The short answer

Many programming textbooks describe abstraction as three kinds: data abstraction, control abstraction and procedural abstraction, which is sometimes called functional abstraction. The names and the exact split vary between sources, so treat this as one common way to organize the idea rather than a formal rule.

What abstraction means

Abstraction means showing what something does while hiding how it does it. Someone using a piece of code needs to know what to ask for, not every step taken to produce the answer.

Data abstraction

Data abstraction hides how information is stored and exposes only the operations on it. In C++, this is usually done with private members and public functions.

class Counter {
public:
    void increment() { ++count_; }
    int value() const { return count_; }

private:
    int count_ = 0;   // Callers never touch this directly
};

Code that uses Counter only calls increment() and value(). The class could later store its count differently, and callers would not need to change. An abstract class takes this idea further: it lists the operations a type supports and leaves the details to each derived class. For the rules and a full example, see the c abstract class guide.

Procedural abstraction

Procedural (functional) abstraction gives a set of steps a name, so callers can use the name without repeating the steps.

#include <cmath>

double point_distance(double x1, double y1, double x2, double y2) {
    return std::sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}

A caller writes point_distance(0, 0, 3, 4) and gets back 5 without needing to remember the formula.

Control abstraction

Control abstraction hides the details of how a program moves from one step to the next, so you can state the pattern you want.

for (int i = 0; i < 5; ++i) {
    std::cout << i << "\n";
}

The for loop manages the counter and the repeated jump back to the top. The code only states how many times to repeat.

Where this leaves you

The three kinds overlap. One function can be both procedural and data abstraction at once, and a loop is a piece of control abstraction that often works on data. If a course or exam asks for the three types, use the labels from that course.

The complete guide to abstract classes

Abstract Classes in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

stringstream in C++

stringstream in C++ explained: how the <sstream> classes read and write text in memory, convert strings and numbers, split text, and avoid common mistakes.

stringstream 4 min read

List vs Array in C++

Compare C++ arrays, std::array, std::vector and std::list by memory layout, element access and insertion cost, with code and a simple rule for choosing.

List vs Array 5 min read