Abstraction example
1class BankAccount:
2def deposit(self, amt): # PUBLIC
3self._validate() # Hidden
4self.balance += amt
5def _validate(self): # PRIVATE
6# Complex validation logic
Abstraction shows only essential features and hides complex internal details from the user.
You call a simple method. The messy details stay inside the class.
Abstraction means exposing only the necessary details and hiding the internal complexity. You interact with the interface, not the implementation.
classDiagram
class BankAccount {
+deposit(amt)
+withdraw(amt)
-_validate()
-balance: int
}
note for BankAccount "Public: deposit(), withdraw()\nPrivate: _validate(), balance" as N1
You drive a car by using the steering wheel, pedals, and buttons. You don't need to know how the engine works. The complex internal details are hidden behind a simple interface.