1
Abstraction and Abstract Class
OOP
Abstraction shows only the essential features and hides the details. Example: you press the brake without knowing how the brake system works.
In C++ a class with at least one pure virtual function (= 0) is an abstract class. It cannot be instantiated; child classes must implement the function.
class Payment { // abstract class
public:
virtual void pay(double amount) = 0; // pure virtual
};
class Bkash : public Payment {
public:
void pay(double amount) override { cout << "Paid " << amount << " by bKash\n"; }
};
// Payment p; // error: cannot create an abstract object
Payment *p = new Bkash();
p->pay(500);