TeachMate
My ProgressJoin Session

Abstraction

0/2 completed · ~0h 5m

All Topics
OOPLearnAbstraction
1 / 2

Abstraction

beginner
2 min read

Abstraction hides complex implementation details and shows only the essential features of an object.

Two Levels of Abstraction

  • Class abstraction: Hide implementation behind a clean interface
  • Physical abstraction: Abstract base classes with pure virtual functions

Why Abstract?

  • Reduce complexity for the user
  • Focus on WHAT an object does, not HOW
  • Allow implementation changes without breaking code

Example

A car driver uses steering wheel and pedals (interface) without knowing how the engine works (implementation).

Abstract Classes

  • Contain at least one pure virtual function (= 0)
  • Cannot be instantiated directly
  • Serve as templates for derived classes
class Shape {
public:
    virtual double area() = 0;  // Pure virtual
    virtual void draw() = 0;    // Pure virtual
};

Interfaces in C++

An interface is a class with ONLY pure virtual functions. C++ doesn't have a separate interface keyword, but this pattern is common.

Key takeaway: Abstraction hides complexity behind a clean interface — use abstract classes and pure virtual functions to define contracts that derived classes must follow.

TeachMate - Interactive learning platform for bachelor students

HomeLearnJoin Session|2 Subjects